Class: Putpaws::Provision::State

Inherits:
Object
  • Object
show all
Defined in:
lib/putpaws/provision/state.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, data:) ⇒ State

Returns a new instance of State.



14
15
16
17
18
19
# File 'lib/putpaws/provision/state.rb', line 14

def initialize(path:, data:)
  @path = path
  @data = data
  @data[:resources] ||= {}
  @data[:steps] ||= {}
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



13
14
15
# File 'lib/putpaws/provision/state.rb', line 13

def data
  @data
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/putpaws/provision/state.rb', line 13

def path
  @path
end

Class Method Details

.load(config) ⇒ Object



7
8
9
10
11
# File 'lib/putpaws/provision/state.rb', line 7

def self.load(config)
  path = config.dir.join('state.json')
  data = path.exist? ? JSON.parse(File.read(path), symbolize_names: true) : {}
  new(path: path.to_s, data: data)
end

Instance Method Details

#mark_step!(name, status) ⇒ Object



34
35
36
37
# File 'lib/putpaws/provision/state.rb', line 34

def mark_step!(name, status)
  steps[name.to_sym] = status
  save!
end

#merge_resources!(outputs) ⇒ Object



29
30
31
32
# File 'lib/putpaws/provision/state.rb', line 29

def merge_resources!(outputs)
  resources.merge!(outputs.map{|k, v| [k.to_sym, v]}.to_h)
  save!
end

#resourcesObject



21
22
23
# File 'lib/putpaws/provision/state.rb', line 21

def resources
  data[:resources]
end

#save!Object



39
40
41
42
# File 'lib/putpaws/provision/state.rb', line 39

def save!
  data[:updated_at] = Time.now.to_s
  Util.write_json(path, data)
end

#stepsObject



25
26
27
# File 'lib/putpaws/provision/state.rb', line 25

def steps
  data[:steps]
end