Class: Grably::Job::Manifest

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

Overview

Manifest file with job data. Manifest keeps information about previous run including passed arguments and output file digests

Constant Summary collapse

MANIFEST =

Manifest file location relative to jobdir

'.manifest'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(job_dir) ⇒ Manifest

Returns a new instance of Manifest.



14
15
16
17
18
# File 'lib/grably/job/manifest.rb', line 14

def initialize(job_dir)
  @job_dir = job_dir
  @data = OpenStruct.new(src: {}, srcs: {}, opt: {}, result: nil, meta: {})
  @manifest_file = File.join(job_dir, MANIFEST)
end

Instance Attribute Details

#manifest_fileObject (readonly)

Returns the value of attribute manifest_file.



12
13
14
# File 'lib/grably/job/manifest.rb', line 12

def manifest_file
  @manifest_file
end

Instance Method Details

#dumpObject



58
59
60
# File 'lib/grably/job/manifest.rb', line 58

def dump
  save_obj(manifest_file, @data)
end

#loadObject



54
55
56
# File 'lib/grably/job/manifest.rb', line 54

def load
  @data = load_obj(manifest_file) if File.exist?(manifest_file)
end

#metaObject



46
47
48
# File 'lib/grably/job/manifest.rb', line 46

def meta
  @data.meta
end

#removeObject



62
63
64
# File 'lib/grably/job/manifest.rb', line 62

def remove
  FileUtils.rm_f(manifest_file)
end

#resultObject



50
51
52
# File 'lib/grably/job/manifest.rb', line 50

def result
  @data.result.first
end

#result=(products) ⇒ Object



41
42
43
44
# File 'lib/grably/job/manifest.rb', line 41

def result=(products)
  digests = Grably::Digest.digest(*products)
  @data.result = [products, digests]
end

#update(name, type, value, update_hook) ⇒ Object

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/grably/job/manifest.rb', line 20

def update(name, type, value, update_hook) # rubocop:disable Metrics/MethodLength,  Metrics/AbcSize
  case type
  when :src
    old_value, old_digest = @data.src[name]
    new_digest = Grably::Digest.digest(value).first
  when :srcs
    old_value, old_digest = @data.srcs[name]
    new_digest = Grably::Digest.digest(*value)
  when :opt
    old_value, _old_digest = @data.opt[name]
    old_digest = nil
    new_digest = nil
  else
    raise ArgumentError, 'Invalid type: ' + type
  end

  @data.send(type)[name] = [value, new_digest]
  update_hook.call(name, type, old_value, old_digest, value, new_digest)
  [old_value, old_digest]
end