Class: Interactify::Dsl::IfInteractor

Inherits:
Object
  • Object
show all
Defined in:
lib/interactify/dsl/if_interactor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(evaluating_receiver, condition, succcess_arg, failure_arg, caller_info:) ⇒ IfInteractor

Returns a new instance of IfInteractor.



16
17
18
19
20
21
22
# File 'lib/interactify/dsl/if_interactor.rb', line 16

def initialize(evaluating_receiver, condition, succcess_arg, failure_arg, caller_info:)
  @evaluating_receiver = evaluating_receiver
  @condition = condition
  @success_arg = succcess_arg
  @failure_arg = failure_arg
  @caller_info = caller_info
end

Instance Attribute Details

#caller_infoObject (readonly)

Returns the value of attribute caller_info.



9
10
11
# File 'lib/interactify/dsl/if_interactor.rb', line 9

def caller_info
  @caller_info
end

#conditionObject (readonly)

Returns the value of attribute condition.



9
10
11
# File 'lib/interactify/dsl/if_interactor.rb', line 9

def condition
  @condition
end

#evaluating_receiverObject (readonly)

Returns the value of attribute evaluating_receiver.



9
10
11
# File 'lib/interactify/dsl/if_interactor.rb', line 9

def evaluating_receiver
  @evaluating_receiver
end

Class Method Details

.attach_klass(evaluating_receiver, condition, succcess_interactor, failure_interactor, caller_info:) ⇒ Object



11
12
13
14
# File 'lib/interactify/dsl/if_interactor.rb', line 11

def self.attach_klass(evaluating_receiver, condition, succcess_interactor, failure_interactor, caller_info:)
  ifable = new(evaluating_receiver, condition, succcess_interactor, failure_interactor, caller_info:)
  ifable.attach_klass
end

Instance Method Details

#attach_klassObject



47
48
49
50
51
# File 'lib/interactify/dsl/if_interactor.rb', line 47

def attach_klass
  name = if_klass_name
  namespace.const_set(name, klass)
  namespace.const_get(name)
end

#failure_interactorObject



28
29
30
# File 'lib/interactify/dsl/if_interactor.rb', line 28

def failure_interactor
  @failure_interactor ||= build_chain(@failure_arg, false)
end

#if_klass_nameObject



57
58
59
60
61
62
63
64
65
# File 'lib/interactify/dsl/if_interactor.rb', line 57

def if_klass_name
  @if_klass_name ||=
    begin
      prefix = condition.is_a?(Proc) ? "Proc" : condition
      prefix = "If#{prefix.to_s.camelize}"

      UniqueKlassName.for(namespace, prefix)
    end
end

#klassObject

allows us to dynamically create an interactor chain that iterates over the packages and uses the passed in each_loop_klasses



35
36
37
# File 'lib/interactify/dsl/if_interactor.rb', line 35

def klass
  IfKlass.new(self).klass
end

#klass_basisObject

so we have something to attach subclasses to during building of the outer class, before we finalize the outer If class



41
42
43
44
45
# File 'lib/interactify/dsl/if_interactor.rb', line 41

def klass_basis
  @klass_basis ||= Class.new do
    include Interactify
  end
end

#namespaceObject



53
54
55
# File 'lib/interactify/dsl/if_interactor.rb', line 53

def namespace
  evaluating_receiver
end

#success_interactorObject



24
25
26
# File 'lib/interactify/dsl/if_interactor.rb', line 24

def success_interactor
  @success_interactor ||= build_chain(@success_arg, true)
end