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 19 20 21 22 23 24 25 |
# File 'lib/eco/api/usecases/use_case.rb', line 10 def initialize(name, type:, root:, &block) invalid_type_err = InvalidType.new( "Invalid type for '#{name}'.", type: type, types: self.class.types ) raise invalid_type_err unless self.class.valid_type?(type) super() 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
33 34 35 36 37 |
# File 'lib/eco/api/usecases/use_case.rb', line 33 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.
72 73 74 |
# File 'lib/eco/api/usecases/use_case.rb', line 72 def classed_definition callback_self if callback_from_loader? end |
#launch(io: nil, **kargs) ⇒ Eco::API::UseCases::UseCaseIO
Actual launch of the usecase
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/eco/api/usecases/use_case.rb', line 55 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
39 40 41 42 43 44 |
# File 'lib/eco/api/usecases/use_case.rb', line 39 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
27 28 29 30 31 |
# File 'lib/eco/api/usecases/use_case.rb', line 27 def source_object return nil unless callback_from_loader? callback_self end |