Class: Kitsune::Kit::Operations::ServiceState

Inherits:
Object
  • Object
show all
Defined in:
lib/kitsune/kit/operations/service_state.rb

Instance Method Summary collapse

Constructor Details

#initialize(state_store:, environment:, resource:) ⇒ ServiceState

Returns a new instance of ServiceState.



7
8
9
10
11
# File 'lib/kitsune/kit/operations/service_state.rb', line 7

def initialize(state_store:, environment:, resource:)
  @state_store = state_store
  @environment = environment
  @resource = resource
end

Instance Method Details

#currentObject



13
# File 'lib/kitsune/kit/operations/service_state.rb', line 13

def current = state_store.read(environment).dig("resources", resource)

#delete(action) ⇒ Object



39
40
41
42
43
44
# File 'lib/kitsune/kit/operations/service_state.rb', line 39

def delete(action)
  update do |state|
    state["resources"].delete(resource)
    operation(state, action)
  end
end

#managed?Boolean

Returns:

  • (Boolean)


14
# File 'lib/kitsune/kit/operations/service_state.rb', line 14

def managed? = !!current&.fetch("managed", false)

#record_apply(action, attributes) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/kitsune/kit/operations/service_state.rb', line 16

def record_apply(action, attributes)
  update do |state|
    previous = state["resources"][resource]
    state["resources"][resource] = attributes.merge("previous_state" => previous)
    operation(state, action)
  end
end

#record_removeObject



24
25
26
27
28
29
# File 'lib/kitsune/kit/operations/service_state.rb', line 24

def record_remove
  update do |state|
    state["resources"][resource]["installed"] = false
    operation(state, "remove")
  end
end

#record_rollback(previous) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/kitsune/kit/operations/service_state.rb', line 31

def record_rollback(previous)
  update do |state|
    prior = previous["previous_state"]
    prior ? state["resources"][resource] = prior : state["resources"].delete(resource)
    operation(state, "rollback")
  end
end