class ClearLogic::Service

Attributes

context_class[RW]
logger_class[RW]
logger_instance[RW]
logger_options[RW]

Public Class Methods

build_context() click to toggle source
# File lib/clear_logic/service.rb, line 16
def build_context
  self.context_class = ClearLogic::ContextBuilder.call
end
call(*args) click to toggle source
# File lib/clear_logic/service.rb, line 12
def call(*args)
  new.call(args)
end
context(name, type = nil, **options) click to toggle source
# File lib/clear_logic/service.rb, line 20
def context(name, type = nil, **options)
  context_class.class_eval do
    method = options.delete(:as) || :option
    send(method, name, type, **options)
  end
end
inherited(base) click to toggle source
# File lib/clear_logic/service.rb, line 33
def inherited(base)
  base.class_eval do
    attr_reader :context

    build_context

    logger ClearLogic::Logger::Default

    step :initialize_context

    private

    def initialize_context(args)
      @context = self.class.context_class.new(*args.flatten)
      context.service = self

      success(context)
    end
  end
end
initialize_context(args) click to toggle source
# File lib/clear_logic/service.rb, line 45
def initialize_context(args)
  @context = self.class.context_class.new(*args.flatten)
  context.service = self

  success(context)
end
logger(logger_class, log_all: false, log_path: nil) click to toggle source
# File lib/clear_logic/service.rb, line 27
def logger(logger_class, log_all: false, log_path: nil)
  self.logger_options = { log_all: log_all, log_path: log_path }
  self.logger_class = logger_class
  self.logger_instance = ClearLogic::Logger::Adapter.new(self).logger
end