Class: IIInteractor::Context

Inherits:
Coactive::Context
  • Object
show all
Defined in:
lib/ii_interactor/context.rb

Defined Under Namespace

Classes: Status

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#_blockObject (readonly)

Returns the value of attribute _block.



13
14
15
# File 'lib/ii_interactor/context.rb', line 13

def _block
  @_block
end

#_statusObject (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

Returns:

  • (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/ii_interactor/context.rb', line 42

def stopped?
  @_status.stopped == true
end

#success?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ii_interactor/context.rb', line 34

def success?
  !failure?
end

#to_sObject



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