Class: Seed::Manifest
- Inherits:
-
Object
- Object
- Seed::Manifest
- Defined in:
- lib/seed/manifest.rb
Instance Method Summary collapse
- #appends(paths = []) ⇒ Object
- #current ⇒ Hash
- #diff? ⇒ Boolean
- #generate_manifest ⇒ Object
-
#initialize(configuration) ⇒ Manifest
constructor
A new instance of Manifest.
- #latest ⇒ Hash
- #manifest_path ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Manifest
Returns a new instance of Manifest.
5 6 7 8 |
# File 'lib/seed/manifest.rb', line 5 def initialize(configuration) @configuration = configuration @paths = [] end |
Instance Method Details
#appends(paths = []) ⇒ Object
10 11 12 13 |
# File 'lib/seed/manifest.rb', line 10 def appends(paths = []) @paths << paths @paths.flatten! end |
#current ⇒ Hash
28 29 30 |
# File 'lib/seed/manifest.rb', line 28 def current @current ||= self.generate_manifest end |
#diff? ⇒ Boolean
15 16 17 |
# File 'lib/seed/manifest.rb', line 15 def diff? self.current.hash != self.latest.hash end |
#generate_manifest ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/seed/manifest.rb', line 45 def generate_manifest hash = {} @paths.each do |path| next unless File.exist?(path) content = File.read(path) hash[path] = Digest::SHA256.new.update(content).hexdigest end hash end |
#latest ⇒ Hash
33 34 35 36 37 38 39 |
# File 'lib/seed/manifest.rb', line 33 def latest @configuration.make_tmp_dir open(self.manifest_path, File::RDONLY | File::CREAT) do |io| JSON.load(io) rescue {} end end |
#manifest_path ⇒ Object
41 42 43 |
# File 'lib/seed/manifest.rb', line 41 def manifest_path @configuration.base_path.join('seed_manifest.json') end |
#save ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/seed/manifest.rb', line 19 def save @configuration.make_tmp_dir open(self.manifest_path, File::WRONLY | File::CREAT | File::TRUNC) do |io| JSON.dump(self.current, io) end end |