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
-
#initialize(name, type:, root:, &block) ⇒ UseCase
constructor
A new instance of UseCase.
-
#launch(io: nil, **kargs) ⇒ Object
Actual launch of the usecase.
- #root=(value) ⇒ Object
Methods inherited from BaseCase
Methods included from Common::ClassHelpers
#class_resolver, #descendants, #descendants?, #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
20 21 22 23 24 |
# File 'lib/eco/api/usecases/use_case.rb', line 20 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 |
#launch(io: nil, **kargs) ⇒ Object
Actual launch of the usecase
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/eco/api/usecases/use_case.rb', line 38 def launch(io: nil, **kargs) params = io&.params(keyed: 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.output = @callback.call(*uio.params) @times_launched += 1 end end |