Class: Eco::API::UseCases::UseCase
- Includes:
- Chainer
- Defined in:
- lib/eco/api/usecases/use_case.rb,
lib/eco/api/usecases/use_case/chainer.rb
Direct Known Subclasses
Defined Under Namespace
Modules: Chainer
Constant Summary
Constants included from BaseCase::Model
Constants included from BaseCase::Type
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#times_launched ⇒ Object
readonly
Returns the value of attribute times_launched.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#classed_definition ⇒ Eco::API::Common::Loaders::Base, NilClass
When it was defined from a Loader class it retrieves the object.
-
#initialize(name, type:, root:, model: nil, &block) ⇒ UseCase
constructor
A new instance of UseCase.
-
#launch(io: nil, **kargs) ⇒ Eco::API::UseCases::UseCaseIO
Actual launch of the usecase.
- #root=(value) ⇒ Object
- #source_object ⇒ Object
Methods included from 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, type:, root:, model: nil, &block) ⇒ UseCase
Returns a new instance of UseCase.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/eco/api/usecases/use_case.rb', line 12 def initialize(name, type:, root:, model: nil, &block) validate_type!(type, msg: "Invalid type for '#{name}'.") model ||= self.class.type_to_default_model(type) validate_model!(model, msg: "Invalid model for '#{name}'.") super() self.root = root @callback = block @name = name @type = type @model = model @times_launched = 0 end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/eco/api/usecases/use_case.rb', line 8 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/eco/api/usecases/use_case.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/eco/api/usecases/use_case.rb', line 9 def end |
#times_launched ⇒ Object (readonly)
Returns the value of attribute times_launched.
10 11 12 |
# File 'lib/eco/api/usecases/use_case.rb', line 10 def times_launched @times_launched end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/eco/api/usecases/use_case.rb', line 8 def type @type end |
Instance Method Details
#classed_definition ⇒ Eco::API::Common::Loaders::Base, NilClass
When it was defined from a Loader class it retrieves the object.
71 72 73 |
# File 'lib/eco/api/usecases/use_case.rb', line 71 def classed_definition callback_self if callback_from_loader? end |
#launch(io: nil, **kargs) ⇒ Eco::API::UseCases::UseCaseIO
Actual launch of the usecase
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/eco/api/usecases/use_case.rb', line 52 def launch(io: nil, **kargs) params = io&.params(keyed: true, all: true) || {} kargs = params.merge(kargs).merge(usecase: self) UseCaseIO.new(**kargs).tap do |uio| = uio. uio.session.log(:debug) { "#{self.class}: going to process '#{name}'" } (uio) if callback_from_loader? uio.output = callback.call(*uio.params) @times_launched += 1 end end |
#root=(value) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/eco/api/usecases/use_case.rb', line 34 def root=(value) msg = "Root should be a Eco::API::UseCases. Given: #{value.class}" raise ArgumentError, msg unless value.is_a?(Eco::API::UseCases) @root = value end |
#source_object ⇒ Object
28 29 30 31 32 |
# File 'lib/eco/api/usecases/use_case.rb', line 28 def source_object return unless callback_from_loader? callback_self end |