Class: Dopi::StateStore

Inherits:
Object
  • Object
show all
Defined in:
lib/dopi/state_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(plan_name, plan_store) ⇒ StateStore

Returns a new instance of StateStore.



8
9
10
11
12
# File 'lib/dopi/state_store.rb', line 8

def initialize(plan_name, plan_store)
  @plan_store  = plan_store
  @plan_name   = plan_name
  @state_store = @plan_store.state_store(plan_name, 'dopi')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



45
46
47
# File 'lib/dopi/state_store.rb', line 45

def method_missing(m, *args, &block)
  @state_store.send(m, *args, &block)
end

Instance Method Details

#persist_state(plan) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/dopi/state_store.rb', line 30

def persist_state(plan)
  @state_store.transaction do
    plan_state = plan.state_hash
    Dopi.log.debug('Persisting plan state:')
    Dopi.log.debug(plan_state)
    @state_store[:state] = plan_state
  end
end

#state_hashObject



39
40
41
42
43
# File 'lib/dopi/state_store.rb', line 39

def state_hash
  @state_store.transaction(true) do
    @state_store[:state] || {}
  end
end

#update(options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dopi/state_store.rb', line 14

def update(options = {})
  if options[:clear]
    clear(options)
  elsif options[:ignore]
    ignore(options)
  else
    update_state(options)
  end
rescue DopCommon::UnknownVersionError => e
  Dopi.log.warn("The state has an unknown plan version #{e.message}.")
  Dopi.log.warn("Please update with the 'clear' or 'ignore' option")
rescue => e
  Dopi.log.error("An error occured during update: #{e.message}")
  Dopi.log.error("Please update with the 'clear' or 'ignore' option")
end