Class: Eco::API::UseCases::BaseIO

Inherits:
BaseCase show all
Includes:
Chaining, Validations, Language::AuxiliarLogger, Language::Methods::DslAble
Defined in:
lib/eco/api/usecases/base_io.rb,
lib/eco/api/usecases/base_io/chaining.rb,
lib/eco/api/usecases/base_io/validations.rb

Overview

Basic class to manage InputOuput for usecases

Direct Known Subclasses

UseCaseIO

Defined Under Namespace

Modules: Chaining, Validations

Constant Summary

Constants included from Eco::API::UseCases::BaseCase::Model

Eco::API::UseCases::BaseCase::Model::MODELS

Constants included from Eco::API::UseCases::BaseCase::Type

Eco::API::UseCases::BaseCase::Type::TYPES

Instance Attribute Summary collapse

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Chaining

#chained, #process_case

Methods included from Language::AuxiliarLogger

#log

Methods included from Language::Methods::DslAble

#evaluate, #method_missing, #respond_to_missing?

Methods included from Language::Klass::InheritableClassVars

#inheritable_attrs, #inheritable_class_vars, #inherited

Methods included from Language::Klass::Naming

#instance_variable_name, #to_constant

Methods included from Language::Klass::Hierarchy

#descendants, #descendants?

Methods included from Language::Klass::Builder

#new_class

Methods included from Language::Klass::Uid

#uid

Methods included from Language::Klass::Resolver

#class_resolver, #resolve_class

Methods included from Language::Klass::Const

#if_const, #redef_without_warning

Constructor Details

#initialize(session:, type: nil, model: nil, input: nil, data: nil, options: {}, output: nil, validate: true, people: nil) ⇒ BaseIO

Returns a new instance of BaseIO.

Parameters:

  • type (Symbol) (defaults to: nil)

    a valid type (among self.class.types)

  • input (Eco::API::Common::People::Entries, Eco::API::Organization::People) (defaults to: nil)

    the input data of reference.

  • data (Variant) (defaults to: nil)

    the base objects that sit in the backend. The data as is it exists.

    • people [Eco::API::Organization::People] people object.
  • session (Eco::API:Session)
  • options (Hash) (defaults to: {})

    hash with symbol keys (i.e. behaviour modifiers, cli trackers, filters, etc.)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/eco/api/usecases/base_io.rb', line 26

def initialize( # rubocop:disable Lint/MissingSuper

  session:,
  type:     nil,
  model:    nil,
  input:    nil,
  data:     nil,
  options:  {},
  output:   nil,
  validate: true,
  people:   nil
)
  people  ||= data # backwards-compatibility

  data    ||= people

  self.type  = type  if type
  self.model = model if model

  @output  = output
  @input   = input
  @data    = data
  @session = session
  @options = options

  validate_args! if validate
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Eco::Language::Methods::DslAble

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



15
16
17
# File 'lib/eco/api/usecases/base_io.rb', line 15

def data
  @data
end

#inputObject (readonly)

Returns the value of attribute input.



15
16
17
# File 'lib/eco/api/usecases/base_io.rb', line 15

def input
  @input
end

#modelObject

Returns the value of attribute model.



16
17
18
# File 'lib/eco/api/usecases/base_io.rb', line 16

def model
  @model
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/eco/api/usecases/base_io.rb', line 15

def options
  @options
end

#outputObject

Returns the value of attribute output.



17
18
19
# File 'lib/eco/api/usecases/base_io.rb', line 17

def output
  @output
end

#sessionObject (readonly)

Returns the value of attribute session.



15
16
17
# File 'lib/eco/api/usecases/base_io.rb', line 15

def session
  @session
end

#typeObject

Returns the value of attribute type.



16
17
18
# File 'lib/eco/api/usecases/base_io.rb', line 16

def type
  @type
end

Instance Method Details

#baseEco::API::UseCases::BaseIO

Helper to obtain an BaseIO object from any child class.



79
80
81
82
83
84
85
86
87
# File 'lib/eco/api/usecases/base_io.rb', line 79

def base
  kargs = params(keyed: true).merge({
    type:   type,
    model:  model,
    output: output
  }).slice(*params_for_clone.keys)

  Eco::API::UseCases::BaseIO.new(**kargs)
end

#ioObject

Note:

used for DSLs



59
60
61
# File 'lib/eco/api/usecases/base_io.rb', line 59

def io
  self
end

#new(**kargs) ⇒ Eco::API::UseCases::BaseIO



91
92
93
# File 'lib/eco/api/usecases/base_io.rb', line 91

def new(**kargs)
  self.class.new(**params_for_clone, **kargs)
end

#params(keyed: false, all: false) ⇒ Object

Note:

order matters

Helper to build a Hash of symbol keys or Array with params to do callbacks.



97
98
99
100
101
102
103
104
# File 'lib/eco/api/usecases/base_io.rb', line 97

def params(keyed: false, all: false)
  kargs = {}
  kargs.merge!(input:   input)   if input_required? || all
  kargs.merge!(data:    data)    if data_required?  || all
  kargs.merge!(session: session, options: options)

  keyed ? kargs : kargs.values
end

#peopleObject

TODO:

remove

backwards-compatibility



54
55
56
# File 'lib/eco/api/usecases/base_io.rb', line 54

def people
  data
end