Class: Rcb::Instance

Inherits:
Object
  • Object
show all
Defined in:
lib/rcb/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, state_store:) ⇒ Instance

Returns a new instance of Instance.

Parameters:



14
15
16
17
# File 'lib/rcb/instance.rb', line 14

def initialize(config, state_store:)
  @config = config
  @state_store = state_store || Rcb::StateStore::InMemory
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/rcb/instance.rb', line 11

def config
  @config
end

Instance Method Details

#run!(&block) ⇒ Object



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

def run!(&block)
  result =
    case get_state
    in State::Close => s
      s.run(config, &block)
    in State::Open => s
      s.run(config, &block)
    in s
      raise "Unknown state: #{s}"
    end

  case result
  in Result::Ok[state, result]
    @state_store.update(config.tag, state)
    return result
  in Result::Ng[state, error]
    @state_store.update(config.tag, state)
    raise error
  end
end

#stateObject



40
41
42
# File 'lib/rcb/instance.rb', line 40

def state
  get_state.show_state(config)
end