Class: Omnibus::Manifest

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/omnibus/manifest.rb

Defined Under Namespace

Classes: InvalidManifestFormat, MissingManifestEntry, NotAManifestEntry

Constant Summary collapse

LATEST_MANIFEST_FORMAT =
1

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

included

Constructor Details

#initialize(version = nil, git_rev = nil) ⇒ Manifest

Returns a new instance of Manifest


30
31
32
33
34
# File 'lib/omnibus/manifest.rb', line 30

def initialize(version=nil, git_rev=nil)
  @data = {}
  @build_version = version
  @build_git_revision = git_rev
end

Instance Attribute Details

#build_git_revisionObject (readonly)

Returns the value of attribute build_git_revision


29
30
31
# File 'lib/omnibus/manifest.rb', line 29

def build_git_revision
  @build_git_revision
end

#build_versionObject (readonly)

Returns the value of attribute build_version


29
30
31
# File 'lib/omnibus/manifest.rb', line 29

def build_version
  @build_version
end

Class Method Details

.from_file(filename) ⇒ Object


111
112
113
# File 'lib/omnibus/manifest.rb', line 111

def self.from_file(filename)
  from_hash(JSON.parse(File.read(File.expand_path(filename))))
end

.from_hash(manifest_data) ⇒ Object

Class Methods


94
95
96
97
98
99
100
101
# File 'lib/omnibus/manifest.rb', line 94

def self.from_hash(manifest_data)
  case manifest_data['manifest_format'].to_i
  when 1
    from_hash_v1(manifest_data)
  else
    raise InvalidManifestFormat, "Unknown manifest format version: #{manifest_data['manifest_format']}"
  end
end

.from_hash_v1(manifest_data) ⇒ Object


103
104
105
106
107
108
109
# File 'lib/omnibus/manifest.rb', line 103

def self.from_hash_v1(manifest_data)
  m = Omnibus::Manifest.new(manifest_data['build_version'], manifest_data['build_git_revision'])
  manifest_data['software'].each do |name, entry_data|
    m.add(name, Omnibus::ManifestEntry.new(name, keys_to_syms(entry_data)))
  end
  m
end

Instance Method Details

#add(name, entry) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/omnibus/manifest.rb', line 44

def add(name, entry)
  if ! entry.is_a? Omnibus::ManifestEntry
    raise NotAManifestEntry, "#{entry} is not an Omnibus:ManifestEntry"
  end

  if @data.key?(name)
    log.warn(log_key) { "Overritting existing manifest entry for #{name}" }
  end

  @data[name] = entry
  self
end

#eachObject


57
58
59
60
61
# File 'lib/omnibus/manifest.rb', line 57

def each
  @data.each do |key, entry|
    yield entry
  end
end

#entry_for(name) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/omnibus/manifest.rb', line 36

def entry_for(name)
  if @data.key?(name)
    @data[name]
  else
    raise MissingManifestEntry, "No manifest entry found for #{name}"
  end
end

#entry_namesObject


63
64
65
# File 'lib/omnibus/manifest.rb', line 63

def entry_names
  @data.keys
end

#to_hashObject


67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/omnibus/manifest.rb', line 67

def to_hash
  software_hash = @data.inject({}) do |memo, (k,v)|
    memo[k] = v.to_hash
    memo
  end
  ret = {
    'manifest_format' => LATEST_MANIFEST_FORMAT,
    'software' => software_hash
  }
  ret['build_version'] = build_version if build_version
  ret['build_git_revision'] = build_git_revision if build_git_revision
  ret
end

#to_jsonString

The JSON representation of this build manifest.

Returns:

  • (String)

86
87
88
# File 'lib/omnibus/manifest.rb', line 86

def to_json
  JSON.pretty_generate(to_hash)
end