Class: IIInteractor::Context
- Inherits:
-
Coactive::Context
- Object
- Coactive::Context
- IIInteractor::Context
- Defined in:
- lib/ii_interactor/context.rb
Defined Under Namespace
Classes: Status
Instance Attribute Summary collapse
-
#_block ⇒ Object
readonly
Returns the value of attribute _block.
-
#_status ⇒ Object
readonly
Returns the value of attribute _status.
Instance Method Summary collapse
- #call_block!(*args) ⇒ Object
- #called!(interactor) ⇒ Object
- #fail!(data = {}) ⇒ Object
- #failure? ⇒ Boolean
-
#initialize(data = {}, &block) ⇒ Context
constructor
A new instance of Context.
- #stop!(data = {}) ⇒ Object
- #stopped? ⇒ Boolean
- #success? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(data = {}, &block) ⇒ Context
Returns a new instance of Context.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ii_interactor/context.rb', line 15 def initialize(data = {}, &block) if data.is_a?(IIInteractor::Context) @_block = data._block @_status = data._status else @_block = block @_status = Status.new end super end |
Instance Attribute Details
#_block ⇒ Object (readonly)
Returns the value of attribute _block.
13 14 15 |
# File 'lib/ii_interactor/context.rb', line 13 def _block @_block end |
#_status ⇒ Object (readonly)
Returns the value of attribute _status.
13 14 15 |
# File 'lib/ii_interactor/context.rb', line 13 def _status @_status end |
Instance Method Details
#call_block!(*args) ⇒ Object
30 31 32 |
# File 'lib/ii_interactor/context.rb', line 30 def call_block!(*args) @_block.call(*args) if @_block end |
#called!(interactor) ⇒ Object
58 59 60 |
# File 'lib/ii_interactor/context.rb', line 58 def called!(interactor) @_status.called << interactor end |
#fail!(data = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/ii_interactor/context.rb', line 46 def fail!(data = {}) @_status.failed = true data.each { |k, v| @_data[k] = v } define_accessors!(data.keys) end |
#failure? ⇒ Boolean
38 39 40 |
# File 'lib/ii_interactor/context.rb', line 38 def failure? @_status.failed == true end |
#stop!(data = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/ii_interactor/context.rb', line 52 def stop!(data = {}) @_status.stopped = true data.each { |k, v| @_data[k] = v } define_accessors!(data.keys) end |
#stopped? ⇒ Boolean
42 43 44 |
# File 'lib/ii_interactor/context.rb', line 42 def stopped? @_status.stopped == true end |
#success? ⇒ Boolean
34 35 36 |
# File 'lib/ii_interactor/context.rb', line 34 def success? !failure? end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/ii_interactor/context.rb', line 26 def to_s "#<#{self.class} #{self.class.inspect(@_data)} (#{self.class.inspect(@_status.to_h)})>" end |