Class: Rcb::Instance
- Inherits:
-
Object
- Object
- Rcb::Instance
- Defined in:
- lib/rcb/instance.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config, state_store:) ⇒ Instance
constructor
A new instance of Instance.
- #run!(&block) ⇒ Object
- #state ⇒ Object
Constructor Details
#initialize(config, state_store:) ⇒ Instance
Returns a new instance of Instance.
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
#config ⇒ Object (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 |
#state ⇒ Object
40 41 42 |
# File 'lib/rcb/instance.rb', line 40 def state get_state.show_state(config) end |