Class: Machinery::Manifest
Overview
The Manifest class takes care of handling the JSON representation of system descriptions. It loads and parses the JSON into a hash and validates it against the current schema.
Instance Attribute Summary collapse
-
#hash ⇒ Object
Returns the value of attribute hash.
-
#json ⇒ Object
Returns the value of attribute json.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, json, path = nil) ⇒ Manifest
constructor
A new instance of Manifest.
- #to_hash ⇒ Object
- #validate ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(name, json, path = nil) ⇒ Manifest
Returns a new instance of Manifest.
35 36 37 38 39 40 41 |
# File 'lib/manifest.rb', line 35 def initialize(name, json, path = nil) @name = name @path = path @json = json parse end |
Instance Attribute Details
#hash ⇒ Object
Returns the value of attribute hash.
22 23 24 |
# File 'lib/manifest.rb', line 22 def hash @hash end |
#json ⇒ Object
Returns the value of attribute json.
22 23 24 |
# File 'lib/manifest.rb', line 22 def json @json end |
#name ⇒ Object
Returns the value of attribute name.
22 23 24 |
# File 'lib/manifest.rb', line 22 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
22 23 24 |
# File 'lib/manifest.rb', line 22 def path @path end |
Class Method Details
.load(name, path) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/manifest.rb', line 24 def self.load(name, path) unless File.exist?(path) raise Machinery::Errors::SystemDescriptionNotFound.new( "Couldn't find a system description with the name '#{name}'." ) end json = File.read(path) Machinery::Manifest.new(name, json, path) end |
Instance Method Details
#to_hash ⇒ Object
62 63 64 |
# File 'lib/manifest.rb', line 62 def to_hash @hash end |
#validate ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/manifest.rb', line 43 def validate return unless compatible_json? errors = Machinery::JsonValidator.new(@hash).validate unless errors.empty? Machinery::Ui.warn("Warning: System Description validation errors:") Machinery::Ui.warn(errors.join("\n")) end end |
#validate! ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/manifest.rb', line 53 def validate! return unless compatible_json? errors = Machinery::JsonValidator.new(@hash).validate unless errors.empty? raise Machinery::Errors::SystemDescriptionValidationFailed.new(errors) end end |