Class: Aardi::ContentHashes

Inherits:
Object
  • Object
show all
Defined in:
lib/aardi/content_hashes.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ ContentHashes

Returns a new instance of ContentHashes.



5
6
7
8
# File 'lib/aardi/content_hashes.rb', line 5

def initialize(path)
  @path = path
  read_hashes
end

Instance Method Details

#[](path) ⇒ Object



10
11
12
# File 'lib/aardi/content_hashes.rb', line 10

def [](path)
  @hashes[path]
end

#[]=(path, hash) ⇒ Object



14
15
16
# File 'lib/aardi/content_hashes.rb', line 14

def []=(path, hash)
  @hashes[path] = hash
end

#replace(new_hashes) ⇒ Object



18
19
20
21
# File 'lib/aardi/content_hashes.rb', line 18

def replace(new_hashes)
  @hashes = new_hashes
  @new_hashes = nil
end

#save(new_hashes) ⇒ Object



23
24
25
26
# File 'lib/aardi/content_hashes.rb', line 23

def save(new_hashes)
  replace(new_hashes)
  write
end

#writeObject



28
29
30
31
32
33
# File 'lib/aardi/content_hashes.rb', line 28

def write
  return if new_hashes == @original_hashes

  File.write(@path, @new_hashes)
  puts "Wrote: #{@path}\n"
end