Class: Roll::Metadata

Inherits:
Object
  • Object
show all
Defined in:
lib/roll/metadata.rb

Overview

– TODO: Use POM? If available? –

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(location) ⇒ Metadata

Returns a new instance of Metadata.



13
14
15
16
# File 'lib/roll/metadata.rb', line 13

def initialize(location)
  @location = location
  @cache = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/roll/metadata.rb', line 76

def method_missing(name, *args)
  if @cache.key?(name)
    @cache[name]
  else
    @cache[name] = read(name)
  end
end

Instance Attribute Details

#locationObject (readonly)

TODO: hide most methods



10
11
12
# File 'lib/roll/metadata.rb', line 10

def location
  @location
end

Instance Method Details

#activeObject

Get library active state.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/roll/metadata.rb', line 33

def active
  return @cache[:active] if @cache.key?(:active)
  @cache[:active] = (
    case read(:active).to_s.downcase
    when 'false', 'no'
      false
    else
      true
    end
  )
end

#loadpathObject

Get library loadpath.



54
55
56
57
58
59
60
# File 'lib/roll/metadata.rb', line 54

def loadpath
  @cache[:loadpath] ||= (
    val = read(:loadpath).to_s.strip.split(/\s*\n/)  # TODO: handle YAML
    val = ['lib'] if val.empty?
    val
  )
end

#nameObject

Get library name.



19
20
21
# File 'lib/roll/metadata.rb', line 19

def name
  @cache[:name] ||= read('name')
end

#releasedObject

Get library release date. – TODO: default date to what? ++



49
50
51
# File 'lib/roll/metadata.rb', line 49

def released
  @cache[:released] ||= read(:released) || "1900-01-01"
end

#requiresObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/roll/metadata.rb', line 63

def requires
  @cache[:requires] ||= (
    if entry = read(:requires)
      entry.strip.split("\n").map do |line|
        line.strip.split(/\s+/)
      end
    else
      []
    end
  )
end

#versionObject

Get library version. – TODO: handle VERSION file TODO: handle YAML ++



28
29
30
# File 'lib/roll/metadata.rb', line 28

def version
  @cache[:version] ||= Version.new(read(:version))
end