Class: Plato::Manifest

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/plato/manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contentsObject (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

#mapObject

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

#save_to(path) ⇒ Object



20
21
22
# File 'lib/plato/manifest.rb', line 20

def save_to(path)
  Repo.new(path).set_all(contents)
end