class LightService::Organizer::WithReducerLogDecorator
Attributes
Public Class Methods
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 8 def initialize(organizer, logger:, decorated: WithReducer.new) @decorated = decorated @organizer = organizer decorated.organizer = organizer @logger = logger @logged = false end
Public Instance Methods
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 30 def around_each(handler) decorated.around_each(handler) self end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 35 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
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 18 def with(data = {}) logger.info { "[LightService] - calling organizer <#{organizer}>" } decorated.with(data) logger.info do "[LightService] - keys in context: " \ "#{extract_keys(decorated.context.keys)}" end self end
Private Instance Methods
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 79 def extract_keys(keys) keys.map { |key| ":#{key}" }.join(', ') end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 83 def has_failure?(context) context.respond_to?(:failure?) && context.failure? end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 65 def log_expects(action) return unless defined?(action.expects) && action.expects.any? logger.info("[LightService] - expects: " \ "#{extract_keys(action.expects)}") end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 72 def log_promises(action) return unless defined?(action.promises) && action.promises.any? logger.info("[LightService] - promises: " \ "#{extract_keys(action.promises)}") end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 93 def skip_remaining?(context) context.respond_to?(:skip_remaining?) && context.skip_remaining? end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 87 def write_failure_log(context, action) logger.warn("[LightService] - :-((( <#{action}> has failed...") logger.warn("[LightService] - context message: #{context.message}") @logged = true end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 55 def write_log(action, context) return unless logger.info? logger.info("[LightService] - executing <#{action}>") log_expects(action) log_promises(action) logger.info("[LightService] - keys in context: "\ "#{extract_keys(context.keys)}") end
Source
# File lib/light-service/organizer/with_reducer_log_decorator.rb, line 97 def write_skip_remaining_log(context, action) return unless logger.info? msg = "[LightService] - ;-) <#{action}> has decided " \ "to skip the rest of the actions" logger.info(msg) logger.info("[LightService] - context message: #{context.message}") @logged = true end