Class: ClearLogic::Service

Inherits:
Object
  • Object
show all
Includes:
Result, Dry::Transaction
Defined in:
lib/clear_logic/service.rb

Constant Summary

Constants included from Result

Result::DEFAULT_ERRORS

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.context_classObject

Returns the value of attribute context_class.



9
10
11
# File 'lib/clear_logic/service.rb', line 9

def context_class
  @context_class
end

.logger_classObject

Returns the value of attribute logger_class.



9
10
11
# File 'lib/clear_logic/service.rb', line 9

def logger_class
  @logger_class
end

.logger_instanceObject

Returns the value of attribute logger_instance.



9
10
11
# File 'lib/clear_logic/service.rb', line 9

def logger_instance
  @logger_instance
end

.logger_optionsObject

Returns the value of attribute logger_options.



9
10
11
# File 'lib/clear_logic/service.rb', line 9

def logger_options
  @logger_options
end

Class Method Details

.build_contextObject



16
17
18
# File 'lib/clear_logic/service.rb', line 16

def build_context
  self.context_class = ClearLogic::ContextBuilder.call
end

.call(*args) ⇒ Object



12
13
14
# File 'lib/clear_logic/service.rb', line 12

def call(*args)
  new.call(args)
end

.context(name, type = nil, **options) ⇒ Object



20
21
22
23
24
25
# 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) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 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

.logger(logger_class, log_all: false, log_path: nil) ⇒ Object



27
28
29
30
31
# 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