|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | require "interactify/dsl/unique_klass_name"
|
| 4 | +require "interactify/dsl/if_klass" |
4 | 5 |
|
5 | 6 | module Interactify
|
6 | 7 | module Dsl
|
@@ -30,33 +31,9 @@ def failure_interactor
|
30 | 31 | # allows us to dynamically create an interactor chain
|
31 | 32 | # that iterates over the packages and
|
32 | 33 | # uses the passed in each_loop_klasses
|
33 |
| - # rubocop:disable all |
34 | 34 | def klass
|
35 |
| - this = self |
36 |
| - |
37 |
| - klass_basis.tap do |k| |
38 |
| - k.instance_eval do |
39 |
| - expects do |
40 |
| - required(this.condition) unless this.condition.is_a?(Proc) |
41 |
| - end |
42 |
| - |
43 |
| - define_singleton_method(:source_location) do |
44 |
| - const_source_location this.evaluating_receiver.to_s # [file, line] |
45 |
| - end |
46 |
| - |
47 |
| - define_method(:run!) do |
48 |
| - result = this.condition.is_a?(Proc) ? this.condition.call(context) : context.send(this.condition) |
49 |
| - interactor = result ? this.success_interactor : this.failure_interactor |
50 |
| - interactor&.respond_to?(:call!) ? interactor.call!(context) : interactor&.call(context) |
51 |
| - end |
52 |
| - |
53 |
| - define_method(:inspect) do |
54 |
| - "<#{this.namespace}::#{this.if_klass_name} #{this.condition} ? #{this.success_interactor} : #{this.failure_interactor}>" |
55 |
| - end |
56 |
| - end |
57 |
| - end |
| 35 | + IfKlass.new(self).klass |
58 | 36 | end
|
59 |
| - # rubocop:enable all |
60 | 37 |
|
61 | 38 | # so we have something to attach subclasses to during building
|
62 | 39 | # of the outer class, before we finalize the outer If class
|
@@ -93,7 +70,7 @@ def build_chain(arg, truthiness)
|
93 | 70 |
|
94 | 71 | case arg
|
95 | 72 | when Array
|
96 |
| - name = "If#{condition.to_s.camelize}#{truthiness ? "IsTruthy" : "IsFalsey"}" |
| 73 | + name = "If#{condition.to_s.camelize}#{truthiness ? 'IsTruthy' : 'IsFalsey'}" |
97 | 74 | klass_basis.chain(name, *arg)
|
98 | 75 | else
|
99 | 76 | arg
|
|
0 commit comments