Class: Mantra::Manifest
- Inherits:
-
Object
- Object
- Mantra::Manifest
- Extended by:
- Forwardable
- Includes:
- Ext
- Defined in:
- lib/mantra/manifest.rb,
lib/mantra/manifest/ext.rb,
lib/mantra/manifest/scope.rb,
lib/mantra/manifest/element.rb,
lib/mantra/manifest/hash_element.rb,
lib/mantra/manifest/leaf_element.rb,
lib/mantra/manifest/root_element.rb,
lib/mantra/manifest/array_element.rb,
lib/mantra/manifest/scope/hash_scope.rb,
lib/mantra/manifest/scope/array_scope.rb,
lib/mantra/manifest/scope/empty_scope.rb
Defined Under Namespace
Modules: Ext Classes: ArrayElement, Element, FileNotFoundError, HashElement, LeafElement, RootElement, Scope, UnknownScopeError
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(manifest_object_or_path) ⇒ Manifest
constructor
A new instance of Manifest.
- #save ⇒ Object
- #write(manifest_path) ⇒ Object
Methods included from Ext
Constructor Details
#initialize(manifest_object_or_path) ⇒ Manifest
Returns a new instance of Manifest.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mantra/manifest.rb', line 24 def initialize(manifest_object_or_path) if manifest_object_or_path.is_a?(String) && File.exist?(manifest_object_or_path) manifest_object = YAML.load_file(manifest_object_or_path) self.file = manifest_object_or_path self.root = Element.create(manifest_object) elsif manifest_object_or_path.is_a?(Hash) || manifest_object_or_path.is_a?(Array) self.root = Element.create(manifest_object_or_path) else raise "Don't know how initialize manifest. Expected existing file path or hash, " + "got #{manifest_object_or_path.class.inspect}: #{manifest_object_or_path.inspect}" end end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
19 20 21 |
# File 'lib/mantra/manifest.rb', line 19 def file @file end |
#root ⇒ Object
Returns the value of attribute root.
19 20 21 |
# File 'lib/mantra/manifest.rb', line 19 def root @root end |
Instance Method Details
#save ⇒ Object
41 42 43 44 |
# File 'lib/mantra/manifest.rb', line 41 def save raise FileNotFoundError.new("File is not specified") if self.file.nil? self.write(self.file) end |
#write(manifest_path) ⇒ Object
37 38 39 |
# File 'lib/mantra/manifest.rb', line 37 def write(manifest_path) File.open(manifest_path, 'w') { |f| f.write(self.to_ruby_object.to_yaml) } end |