Class: Eco::API::UseCases::UseCase
- Defined in:
- lib/eco/api/usecases/use_case.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#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
- #chainer ⇒ Object
-
#classed_definition ⇒ Eco::API::Common::Loaders::Base, NilClass
When it was defined from a Loader class it retrieves the object.
-
#initialize(name, type:, root:, &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 inherited from BaseCase
Methods included from Common::ClassHelpers
#class_resolver, #descendants, #descendants?, #inheritable_attrs, #inheritable_class_vars, #inherited, #instance_variable_name, #new_class, #resolve_class, #to_constant
Constructor Details
#initialize(name, type:, root:, &block) ⇒ UseCase
Returns a new instance of UseCase.
10 11 12 13 14 15 16 17 18 |
# File 'lib/eco/api/usecases/use_case.rb', line 10 def initialize(name, type:, root:, &block) raise InvalidType.new("Invalid type for '#{name}'.", type: type, types: self.class.types) unless self.class.valid_type?(type) self.root = root @callback = block @name = name @type = type @times_launched = 0 end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/eco/api/usecases/use_case.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/eco/api/usecases/use_case.rb', line 8 def @options end |
#times_launched ⇒ Object (readonly)
Returns the value of attribute times_launched.
7 8 9 |
# File 'lib/eco/api/usecases/use_case.rb', line 7 def times_launched @times_launched end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/eco/api/usecases/use_case.rb', line 7 def type @type end |
Instance Method Details
#chainer ⇒ Object
25 26 27 28 29 |
# File 'lib/eco/api/usecases/use_case.rb', line 25 def chainer # TODO: root is a Eco::API::UseCases that will not point to this new case. # => Moreover, the name and type will be the same as self Eco::API::UseCases::UseCaseChain.new(usecase: self, root: @root) end |
#classed_definition ⇒ Eco::API::Common::Loaders::Base, NilClass
When it was defined from a Loader class it retrieves the object.
59 60 61 |
# File 'lib/eco/api/usecases/use_case.rb', line 59 def classed_definition callback_self if callback_from_loader? end |
#launch(io: nil, **kargs) ⇒ Eco::API::UseCases::UseCaseIO
Actual launch of the usecase
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/eco/api/usecases/use_case.rb', line 44 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| @options = uio. uio.session.logger.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
31 32 33 34 |
# File 'lib/eco/api/usecases/use_case.rb', line 31 def root=(value) raise "Root should be a Eco::API::UseCases. Given: #{value.class}" if !value.is_a?(Eco::API::UseCases) @root = value end |
#source_object ⇒ Object
20 21 22 23 |
# File 'lib/eco/api/usecases/use_case.rb', line 20 def source_object return nil unless callback_from_loader? callback_self end |