Module: Interactify::Dsl
- Defined in:
- lib/interactify/dsl.rb,
lib/interactify/dsl/wrapper.rb,
lib/interactify/dsl/if_klass.rb,
lib/interactify/dsl/organizer.rb,
lib/interactify/dsl/each_chain.rb,
lib/interactify/dsl/if_interactor.rb,
lib/interactify/dsl/unique_klass_name.rb
Defined Under Namespace
Modules: Organizer, UniqueKlassName Classes: EachChain, IfInteractor, IfKlass, Wrapper
Instance Method Summary collapse
-
#chain(klass_name, *chained_klasses, expect: []) ⇒ Object
this method allows us to dynamically create an organizer from a name, and a chain of interactors.
-
#each(plural_resource_name, *each_loop_klasses) ⇒ Object
creates a class in the attach_klass_to’s namespace e.g.
- #if(condition, success_arg, failure_arg = nil) ⇒ Object
Instance Method Details
#chain(klass_name, *chained_klasses, expect: []) ⇒ Object
this method allows us to dynamically create an organizer from a name, and a chain of interactors
e.g.
Interactify.chain(:SomeClass, A, B, C, expect: [:foo, :bar])
is the programmable equivalent to
class SomeClass
include Interactify
organize(A, B, C)
end
it will attach the generate class to the currenct class and use the class name passed in rubocop:disable all
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/interactify/dsl.rb', line 57 def chain(klass_name, *chained_klasses, expect: []) expectations = expect klass = Class.new do # class EvaluatingNamespace::SomeClass include Interactify # include Interactify expect(*expectations) if expectations.any? # expect :foo, :bar define_singleton_method(:source_location) do # def self.source_location source_location # [file, line] end # end organize(*chained_klasses) # organize(A, B, C) end # end # attach the class to the calling namespace where_to_attach = self.binding.receiver klass_name = UniqueKlassName.for(where_to_attach, klass_name) where_to_attach.const_set(klass_name, klass) end |
#each(plural_resource_name, *each_loop_klasses) ⇒ Object
creates a class in the attach_klass_to’s namespace e.g.
in Orders Interactify.each(self, :packages, A, B, C)
will create a class called Orders::EachPackage, that will call the interactor chain A, B, C for each package in the context
17 18 19 20 21 22 23 |
# File 'lib/interactify/dsl.rb', line 17 def each(plural_resource_name, *each_loop_klasses) EachChain.attach_klass( self, plural_resource_name, *each_loop_klasses ) end |
#if(condition, success_arg, failure_arg = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/interactify/dsl.rb', line 25 def if(condition, success_arg, failure_arg = nil) then_else = if success_arg.is_a?(Hash) && failure_arg.nil? success_arg.slice(:then, :else) else { then: success_arg, else: failure_arg } end IfInteractor.attach_klass( self, condition, then_else[:then], then_else[:else] ) end |