Class: Eco::API::UseCases::UseCaseChain
- Includes:
- Chaining
- Defined in:
- lib/eco/api/usecases/use_case_chain.rb,
lib/eco/api/usecases/use_case_chain/chaining.rb
Overview
Class that enables to chain multiple UseCase
Defined Under Namespace
Modules: Chaining
Constant Summary
Constants included from Chaining
Constants included from BaseCase::Model
Constants included from BaseCase::Type
Instance Attribute Summary
Attributes inherited from UseCase
#model, #name, #options, #times_launched, #type
Instance Method Summary collapse
-
#initialize(name = nil, root:, type: nil, model: nil, usecase: nil, &block) ⇒ UseCaseChain
constructor
A new instance of UseCaseChain.
- #launch(io: nil, **kargs) ⇒ Object
- #root=(value) ⇒ Object
Methods included from Chaining
Methods inherited from UseCase
#classed_definition, #source_object
Methods included from Eco::API::UseCases::UseCase::Chainer
Methods included from Language::Klass::InheritableClassVars
#inheritable_attrs, #inheritable_class_vars, #inherited
Methods included from Language::Klass::Naming
#instance_variable_name, #to_constant
Methods included from Language::Klass::Hierarchy
Methods included from Language::Klass::Builder
Methods included from Language::Klass::Uid
Methods included from Language::Klass::Resolver
#class_resolver, #resolve_class
Methods included from Language::Klass::Const
#if_const, #redef_without_warning
Constructor Details
#initialize(name = nil, root:, type: nil, model: nil, usecase: nil, &block) ⇒ UseCaseChain
Returns a new instance of UseCaseChain.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/eco/api/usecases/use_case_chain.rb', line 9 def initialize(name = nil, root:, type: nil, model: nil, usecase: nil, &block) if usecase msg = 'Expected Eco::API::UseCases::UseCase. ' msg << "Given #{usecase.class}" raise msg unless usecase.is_a?(Eco::API::UseCases::UseCase) type = usecase.type name = usecase.name block ||= usecase.callback end super(name, type: type, model: model, root: root, &block) reset_chains! end |
Instance Method Details
#launch(io: nil, **kargs) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/eco/api/usecases/use_case_chain.rb', line 34 def launch(io: nil, **kargs) super.tap do |uio| next if resolved_chains.empty? resolved_chains.each do |usecase| uio = usecase.launch(io: uio.chain(usecase: usecase)) end end end |
#root=(value) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/eco/api/usecases/use_case_chain.rb', line 25 def root=(value) return super unless @resolved_chains # rubocop:disable Lint/ReturnInVoidContext msg = 'You cannot change root Eco::API::UseCases ' msg << 'once the chains have been resolved' raise msg end |