Class: Eco::API::UseCases::BaseIO
- Defined in:
- lib/eco/api/usecases/base_io.rb
Overview
Basic class to manage InputOuput for usecases
Direct Known Subclasses
Defined Under Namespace
Classes: MissingParameter
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#output ⇒ Object
Returns the value of attribute output.
-
#people ⇒ Object
readonly
Returns the value of attribute people.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes included from Language::AuxiliarLogger
Class Method Summary collapse
Instance Method Summary collapse
-
#base ⇒ Eco::API::UseCases::BaseIO
Helper to obtain an
BaseIO
object from any child class. -
#chained(as: type) ⇒ Eco::API::UseCases::BaseIO
Does the switch from output to result in a new IO object.
-
#initialize(session:, type: nil, input: nil, people: nil, options: {}, output: nil, validate: true) ⇒ BaseIO
constructor
A new instance of BaseIO.
- #new(**kargs) ⇒ Eco::API::UseCases::BaseIO
-
#params(keyed: false, all: false) ⇒ Object
Helper to build a
Hash
of symbol keys orArray
with params to do callbacks. -
#process_case(case_name, case_type, **params) ⇒ Eco::API::UseCases::BaseIO
Shortcut to run a usecase passing this
io
as parameter.
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(session:, type: nil, input: nil, people: nil, options: {}, output: nil, validate: true) ⇒ BaseIO
Returns a new instance of BaseIO.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/eco/api/usecases/base_io.rb', line 43 def initialize( # rubocop:disable Lint/MissingSuper session:, type: nil, input: nil, people: nil, options: {}, output: nil, validate: true ) self.type = type if type if self.type && validate # rubocop:disable Style/IfUnlessModifier validate_args(input: input, people: people, session: session, options: ) end @output = output @input = input @people = people @session = session @options = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Eco::Language::Methods::DslAble
Instance Attribute Details
#input ⇒ Object (readonly)
Returns the value of attribute input.
34 35 36 |
# File 'lib/eco/api/usecases/base_io.rb', line 34 def input @input end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
34 35 36 |
# File 'lib/eco/api/usecases/base_io.rb', line 34 def @options end |
#output ⇒ Object
Returns the value of attribute output.
36 37 38 |
# File 'lib/eco/api/usecases/base_io.rb', line 36 def output @output end |
#people ⇒ Object (readonly)
Returns the value of attribute people.
34 35 36 |
# File 'lib/eco/api/usecases/base_io.rb', line 34 def people @people end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
34 35 36 |
# File 'lib/eco/api/usecases/base_io.rb', line 34 def session @session end |
#type ⇒ Object
Returns the value of attribute type.
35 36 37 |
# File 'lib/eco/api/usecases/base_io.rb', line 35 def type @type end |
Class Method Details
.input_required?(type) ⇒ Boolean
25 26 27 |
# File 'lib/eco/api/usecases/base_io.rb', line 25 def input_required?(type) !valid_type?(type) || %i[import sync].include?(type) end |
.people_required?(type) ⇒ Boolean
29 30 31 |
# File 'lib/eco/api/usecases/base_io.rb', line 29 def people_required?(type) !valid_type?(type) || %i[filter transform sync error_handler export].include?(type) end |
Instance Method Details
#base ⇒ Eco::API::UseCases::BaseIO
Helper to obtain an BaseIO
object from any child class.
69 70 71 72 73 74 75 76 |
# File 'lib/eco/api/usecases/base_io.rb', line 69 def base kargs = params(keyed: true).merge({ type: type, output: output }).slice(:type, :input, :people, :session, :options, :output) # :validate <- ? Eco::API::UseCases::BaseIO.new(**kargs) end |
#chained(as: type) ⇒ Eco::API::UseCases::BaseIO
if there isn't output
it doesn't do the switch,
provided that it preserves the target parameter
(otherise it would blank it)
Does the switch from output to result in a new IO object.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/eco/api/usecases/base_io.rb', line 122 def chained(as: type) # rubocop:disable Naming/MethodParameterName base.tap do |io_base| next unless io_base.output case as when :import io_base.output_be_input! when :filter io_base.output_be_people! # when :transform, :sync, :export, :error_handler, :other end end end |
#new(**kargs) ⇒ Eco::API::UseCases::BaseIO
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/eco/api/usecases/base_io.rb', line 80 def new(**kargs) default = { type: type, input: input, people: people, session: session, options: , output: output, validate: true } self.class.new(**default.merge(kargs)) end |
#params(keyed: false, all: false) ⇒ Object
Helper to build a Hash
of symbol keys or Array
with params to do callbacks.
94 95 96 97 98 99 100 101 |
# File 'lib/eco/api/usecases/base_io.rb', line 94 def params(keyed: false, all: false) kargs = {} kargs.merge!(input: input) if input_required? || all kargs.merge!(people: people) if people_required? || all kargs.merge!(session: session, options: ) keyed ? kargs : kargs.values end |
#process_case(case_name, case_type, **params) ⇒ Eco::API::UseCases::BaseIO
- It swaps
output
toinput
orpeople
depending onself.type
- does this, before the target
case_name
launch and **after
Shortcut to run a usecase passing this io
as parameter
108 109 110 111 112 113 114 115 |
# File 'lib/eco/api/usecases/base_io.rb', line 108 def process_case(case_name, case_type, **params) session.process_case( case_name, io: chained, type: case_type, **params ).chained end |