Class: Seed::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/seed/manifest.rb

Instance Method Summary collapse

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

#currentHash

Returns:

  • (Hash)


28
29
30
# File 'lib/seed/manifest.rb', line 28

def current
  @current ||= self.generate_manifest
end

#diff?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/seed/manifest.rb', line 15

def diff?
  self.current.hash != self.latest.hash
end

#generate_manifestObject



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

#latestHash

Returns:

  • (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_pathObject



41
42
43
# File 'lib/seed/manifest.rb', line 41

def manifest_path
  @configuration.base_path.join('seed_manifest.json')
end

#saveObject



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