Class: Eco::API::UseCases::UseCaseIO

Inherits:
BaseIO show all
Defined in:
lib/eco/api/usecases/use_case_io.rb

Overview

Note:

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

Attributes inherited from BaseIO

#input, #options, #output, #people, #session

Instance Method Summary collapse

Methods inherited from BaseIO

#base, input_required?, people_required?

Methods inherited from BaseCase

valid_type?, validate_type

Constructor Details

#initialize(usecase:, job: nil, **kargs) ⇒ UseCaseIO

Returns a new instance of UseCaseIO.

See Also:



18
19
20
21
22
# File 'lib/eco/api/usecases/use_case_io.rb', line 18

def initialize(usecase:, job: nil, **kargs)
  self.usecase = usecase
  @job         = job
  super(**kargs)
end

Instance Attribute Details

#usecaseEco::API::UseCases::UseCase

the usecase this InputOuput is linked to



10
11
12
# File 'lib/eco/api/usecases/use_case_io.rb', line 10

def usecase
  @usecase
end

Instance Method Details

#chain(usecase:) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/eco/api/usecases/use_case_io.rb', line 66

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)

  case self.type
  when :import
    kargs[:input]  = output
  when :filter
    kargs[:people] = output
  when :transform, :sync, :export, :error_handler
    # no redirections => should it redirect the input?

  end
  self.class.new(kargs)
end

#new(usecase:, **kargs) ⇒ Eco::API::UseCases::UseCaseIO

See Also:



27
28
29
30
31
32
33
# File 'lib/eco/api/usecases/use_case_io.rb', line 27

def new(usecase:, **kargs)
  default = {
    usecase: usecase,
    job:     @job
  }
  super(**default.merge(kargs))
end

#params(keyed: false) ⇒ Object

Same as its superclass but adding usecase parameter

See Also:



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/eco/api/usecases/use_case_io.rb', line 53

def params(keyed: false)
  super(keyed: keyed).tap do |res|
    if keyed
      res.merge!({
        usecase: usecase,
        job:     @job
      })
    else
      res.push(usecase).push(@job)
    end
  end
end

#typeSymbol



43
44
45
# File 'lib/eco/api/usecases/use_case_io.rb', line 43

def type
  @usecase.type
end

#type=(value) ⇒ Object



47
48
49
# File 'lib/eco/api/usecases/use_case_io.rb', line 47

def type=(value)
  raise "Can't modify type depends on the usecase linked to this IO object"
end