Class: Eco::API::UseCases::UseCaseIO
- Defined in:
- lib/eco/api/usecases/use_case_io.rb
Overview
Same as Eco::API::UseCases::BaseIO but:
- includes
type
of usecase - provides a helper to
chain
InputOutput between usecases
InputOutput class for usecases.
Instance Attribute Summary collapse
-
#usecase ⇒ Eco::API::UseCases::UseCase
the usecase this InputOuput is linked to.
Attributes inherited from BaseIO
#input, #options, #output, #people, #session
Attributes included from Language::AuxiliarLogger
Instance Method Summary collapse
- #chain(usecase:) ⇒ Object
-
#initialize(usecase:, job: nil, **kargs) ⇒ UseCaseIO
constructor
A new instance of UseCaseIO.
- #new(usecase:, **kargs) ⇒ Eco::API::UseCases::UseCaseIO
-
#params(keyed: false, all: false) ⇒ Object
Same as its superclass but adding
usecase
andjob
parameters. -
#type ⇒ Symbol
The
type
of the UseCase this InputOuput is linked to. - #type=(value) ⇒ Object
Methods inherited from BaseIO
#base, #chained, input_required?, people_required?, #process_case
Methods included from Language::AuxiliarLogger
Methods included from Language::Methods::DslAble
#evaluate, #method_missing, #respond_to_missing?
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(usecase:, job: nil, **kargs) ⇒ UseCaseIO
Returns a new instance of UseCaseIO.
17 18 19 20 21 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 17 def initialize(usecase:, job: nil, **kargs) self.usecase = usecase @job = job super(**kargs) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Eco::Language::Methods::DslAble
Instance Attribute Details
#usecase ⇒ Eco::API::UseCases::UseCase
the usecase this InputOuput is linked to
9 10 11 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 9 def usecase @usecase end |
Instance Method Details
#chain(usecase:) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 61 def chain(usecase:) raise "It should be a UseCase. Given: #{usecase}" if !usecase.is_a?(UseCase) #aux_io = self.class.new(input: input, people: people, session: session, options: options, usecase: usecase) #kargs = aux_io.params(keyed: true) kargs = params(keyed: true, all: true).merge(usecase: usecase) kargs.delete(:job) case self.type when :import kargs[:input] = output when :filter kargs[:people] = output when :transform, :sync, :export, :error_handler, :other # no redirections => should it redirect the input? end self.class.new(**kargs) end |
#new(usecase:, **kargs) ⇒ Eco::API::UseCases::UseCaseIO
26 27 28 29 30 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 26 def new(usecase:, **kargs) default = { usecase: usecase } default.merge!(job: @job) if @job super(**default.merge(kargs)) end |
#params(keyed: false, all: false) ⇒ Object
Same as its superclass but adding usecase
and job
parameters
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 49 def params(keyed: false, all: false) super(keyed: keyed, all: all).tap do |res| if keyed res.merge!(usecase: usecase) res.merge!(job: @job) if @job else res.push(usecase) res.push(@job) if @job end end end |
#type ⇒ Symbol
Returns the type
of the UseCase this InputOuput is linked to.
39 40 41 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 39 def type @usecase.type end |
#type=(value) ⇒ Object
43 44 45 |
# File 'lib/eco/api/usecases/use_case_io.rb', line 43 def type=(value) raise "Can't modify type depends on the usecase linked to this IO object" end |