Class: FunctionalLightService::Organizer::WithReducerLogDecorator

Inherits:
Object
  • Object
show all
Defined in:
lib/functional-light-service/organizer/with_reducer_log_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organizer, logger:, decorated: WithReducer.new) ⇒ WithReducerLogDecorator

Returns a new instance of WithReducerLogDecorator.



10
11
12
13
14
15
16
17
18
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 10

def initialize(organizer, logger:, decorated: WithReducer.new)
  @decorated = decorated
  @organizer = organizer

  decorated.organizer = organizer

  @logger = logger
  @logged = false
end

Instance Attribute Details

#decoratedObject (readonly)

Returns the value of attribute decorated.



6
7
8
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 6

def decorated
  @decorated
end

#loggedObject (readonly) Also known as: logged?

Returns the value of attribute logged.



6
7
8
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 6

def logged
  @logged
end

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 6

def logger
  @logger
end

#organizerObject (readonly)

Returns the value of attribute organizer.



6
7
8
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 6

def organizer
  @organizer
end

Instance Method Details

#around_each(handler) ⇒ Object



32
33
34
35
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 32

def around_each(handler)
  decorated.around_each(handler)
  self
end

#reduce(*actions) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 37

def reduce(*actions)
  decorated.reduce(*actions) do |context, action|
    next context if logged?

    if has_failure?(context)
      write_failure_log(context, action)
      next context
    end

    if skip_remaining?(context)
      write_skip_remaining_log(context, action)
      next context
    end

    write_log(action, context)
  end
end

#with(data = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/functional-light-service/organizer/with_reducer_log_decorator.rb', line 20

def with(data = {})
  logger.info { "[FunctionalLightService] - calling organizer <#{organizer}>" }

  decorated.with(data)

  logger.info do
    "[FunctionalLightService] -     keys in context: " \
      "#{extract_keys(decorated.context.keys)}"
  end
  self
end