Class: Plato::Manifest
- Inherits:
-
Object
- Object
- Plato::Manifest
- Includes:
- Enumerable
- Defined in:
- lib/plato/manifest.rb
Instance Attribute Summary collapse
-
#codec ⇒ Object
readonly
Returns the value of attribute codec.
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object (also: #store)
- #each(&block) ⇒ Object
-
#initialize(contents = nil, opts = {}) ⇒ Manifest
constructor
A new instance of Manifest.
-
#map(new_codec = nil) ⇒ 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, codec = nil) ⇒ Object
Constructor Details
#initialize(contents = nil, opts = {}) ⇒ Manifest
Returns a new instance of Manifest.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/plato/manifest.rb', line 7 def initialize(contents = nil, opts = {}) opts = { :codec => opts } unless opts.is_a? Hash @codec = opts[:codec] @contents = if contents.nil? {} elsif contents.is_a? Hash contents elsif contents.is_a? String Repo.new(contents, @codec).all &opts[:filter] else raise ArgumentError, "invalid contents" end end |
Instance Attribute Details
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
5 6 7 |
# File 'lib/plato/manifest.rb', line 5 def codec @codec end |
#contents ⇒ Object (readonly)
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
28 29 30 |
# File 'lib/plato/manifest.rb', line 28 def [](key) contents[key] end |
#[]=(key, value) ⇒ Object Also known as: store
32 33 34 |
# File 'lib/plato/manifest.rb', line 32 def []=(key, value) contents[key] = value end |
#each(&block) ⇒ Object
53 54 55 |
# File 'lib/plato/manifest.rb', line 53 def each(&block) contents.each(&block) end |
#map(new_codec = nil) ⇒ 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
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/plato/manifest.rb', line 39 def map(new_codec = nil) new_contents = if block_given? @contents.inject({}) do |hash, (path, data)| new_path_data = yield(path, data) new_path_data ? hash.update(new_path_data) : hash end else @contents.dup end self.class.new(new_contents, new_codec || self.codec) end |