Class: Omnibus::Manifest
- Inherits:
-
Object
- Object
- Omnibus::Manifest
- Includes:
- Logging
- Defined in:
- lib/omnibus/manifest.rb
Defined Under Namespace
Classes: InvalidManifestFormat, MissingManifestEntry, NotAManifestEntry
Constant Summary collapse
- LATEST_MANIFEST_FORMAT =
2
Instance Attribute Summary collapse
-
#build_git_revision ⇒ Object
readonly
Returns the value of attribute build_git_revision.
-
#build_version ⇒ Object
readonly
Returns the value of attribute build_version.
-
#license ⇒ Object
readonly
Returns the value of attribute license.
Class Method Summary collapse
- .from_file(filename) ⇒ Object
-
.from_hash(manifest_data) ⇒ Object
Class Methods.
- .from_hash_v1(manifest_data) ⇒ Object
- .from_hash_v2(manifest_data) ⇒ Object
-
.keys_to_syms(h) ⇒ Object
Utility function to convert a Hash with String keys to a Hash with Symbol keys, recursively.
Instance Method Summary collapse
- #add(name, entry) ⇒ Object
- #each ⇒ Object
- #entry_for(name) ⇒ Object
- #entry_names ⇒ Object
-
#initialize(version = nil, git_rev = nil, license = "Unspecified") ⇒ Manifest
constructor
A new instance of Manifest.
- #to_hash ⇒ Object
-
#to_json ⇒ String
The JSON representation of this build manifest.
Methods included from Logging
Constructor Details
#initialize(version = nil, git_rev = nil, license = "Unspecified") ⇒ Manifest
Returns a new instance of Manifest.
30 31 32 33 34 35 |
# File 'lib/omnibus/manifest.rb', line 30 def initialize(version = nil, git_rev = nil, license = "Unspecified") @data = {} @build_version = version @build_git_revision = git_rev @license = license end |
Instance Attribute Details
#build_git_revision ⇒ Object (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_version ⇒ Object (readonly)
Returns the value of attribute build_version.
29 30 31 |
# File 'lib/omnibus/manifest.rb', line 29 def build_version @build_version end |
#license ⇒ Object (readonly)
Returns the value of attribute license.
29 30 31 |
# File 'lib/omnibus/manifest.rb', line 29 def license @license end |
Class Method Details
.from_file(filename) ⇒ Object
134 135 136 137 138 |
# File 'lib/omnibus/manifest.rb', line 134 def self.from_file(filename) data = File.read(File.(filename)) hash = FFI_Yajl::Parser.parse(data, symbolize_names: true) from_hash(hash) end |
.from_hash(manifest_data) ⇒ Object
Class Methods
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/omnibus/manifest.rb', line 105 def self.from_hash(manifest_data) case manifest_data[:manifest_format].to_i when 1 from_hash_v1(manifest_data) when 2 from_hash_v2(manifest_data) else raise InvalidManifestFormat, "Unknown manifest format version: #{manifest_data[:manifest_format]}" end end |
.from_hash_v1(manifest_data) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/omnibus/manifest.rb', line 116 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 |
.from_hash_v2(manifest_data) ⇒ Object
124 125 126 127 128 129 130 131 132 |
# File 'lib/omnibus/manifest.rb', line 124 def self.from_hash_v2(manifest_data) m = Omnibus::Manifest.new(manifest_data[:build_version], manifest_data[:build_git_revision], manifest_data[:license]) manifest_data[:software].each do |name, entry_data| m.add(name, Omnibus::ManifestEntry.new(name, keys_to_syms(entry_data))) end m end |
.keys_to_syms(h) ⇒ Object
Utility function to convert a Hash with String keys to a Hash with Symbol keys, recursively.
146 147 148 149 150 151 152 153 154 155 |
# File 'lib/omnibus/manifest.rb', line 146 def self.keys_to_syms(h) h.inject({}) do |memo, (k, v)| memo[k.to_sym] = if v.is_a? Hash keys_to_syms(v) else v end memo end end |
Instance Method Details
#add(name, entry) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omnibus/manifest.rb', line 46 def add(name, entry) unless entry.is_a? Omnibus::ManifestEntry raise NotAManifestEntry, "#{entry} is not an Omnibus:ManifestEntry" end name_sym = name.to_sym if @data.key?(name_sym) log.warn(log_key) { "Overritting existing manifest entry for #{name}" } end @data[name_sym] = entry self end |
#each ⇒ Object
60 61 62 63 64 |
# File 'lib/omnibus/manifest.rb', line 60 def each @data.each do |key, entry| yield entry end end |
#entry_for(name) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/omnibus/manifest.rb', line 37 def entry_for(name) name_sym = name.to_sym if @data.key?(name_sym) @data[name_sym] else raise MissingManifestEntry, "No manifest entry found for #{name}" end end |
#entry_names ⇒ Object
66 67 68 |
# File 'lib/omnibus/manifest.rb', line 66 def entry_names @data.keys end |
#to_hash ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/omnibus/manifest.rb', line 70 def to_hash software_hash = @data.inject({}) do |memo, (k, v)| h = v.to_hash h[:locked_source].delete(:authorization) if h[:locked_source] memo[k] = h memo end = Omnibus::BuildSystemMetadata.to_hash ret = { manifest_format: LATEST_MANIFEST_FORMAT, software: software_hash, } ret[:build_system_metadata] = if ret[:build_version] = build_version if build_version ret[:build_git_revision] = build_git_revision if build_git_revision ret[:license] = license ret end |
#to_json ⇒ String
The JSON representation of this build manifest.
97 98 99 |
# File 'lib/omnibus/manifest.rb', line 97 def to_json FFI_Yajl::Encoder.encode(to_hash, pretty: true) end |