Class: Plato::Manifest
- Inherits:
-
Object
- Object
- Plato::Manifest
- Includes:
- Enumerable
- Defined in:
- lib/plato/manifest.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
(also: #to_h, #to_hash)
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object (also: #store)
- #each(&block) ⇒ Object
-
#initialize(contents = nil) ⇒ Manifest
constructor
A new instance of Manifest.
-
#map ⇒ Object
if given a block, block should return a hash of the new path and new data, or nil if the file should be skipped.
- #save_to(path) ⇒ Object
Constructor Details
#initialize(contents = nil) ⇒ Manifest
Returns a new instance of Manifest.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/plato/manifest.rb', line 9 def initialize(contents = nil) @contents = if contents.nil? {} elsif contents.respond_to? :to_hash contents.to_hash else raise ArgumentError, "invalid contents" end end |
Instance Attribute Details
#contents ⇒ Object (readonly) Also known as: to_h, to_hash
Returns the value of attribute contents.
5 6 7 |
# File 'lib/plato/manifest.rb', line 5 def contents @contents end |
Instance Method Details
#[](key) ⇒ Object
24 25 26 |
# File 'lib/plato/manifest.rb', line 24 def [](key) contents[key] end |
#[]=(key, value) ⇒ Object Also known as: store
28 29 30 |
# File 'lib/plato/manifest.rb', line 28 def []=(key, value) contents[key] = value end |
#each(&block) ⇒ Object
45 46 47 |
# File 'lib/plato/manifest.rb', line 45 def each(&block) contents.each(&block) end |
#map ⇒ Object
if given a block, block should return a hash of the new path and new data, or nil if the file should be skipped
35 36 37 38 39 40 41 42 43 |
# File 'lib/plato/manifest.rb', line 35 def map new_contents = @contents.inject({}) do |hash, (path, data)| new_path_data = yield(path, data) new_path_data ? hash.update(new_path_data) : hash end self.class.new(new_contents) end |