Class: ClearLogic::ContextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/clear_logic/context/builder.rb

Class Method Summary collapse

Class Method Details

.callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/clear_logic/context/builder.rb', line 5

def self.call
  Class.new do
    extend ::Dry::Initializer

    attr_reader :args
    attr_accessor :catched_error, :failure_error, :service, :exit_success, :step

    def initialize(*args)
      @args = args
      super(*args)
    end

    def [](key)
      @additional_opts ||= {}
      @additional_opts[key]
    end

    def []=(key, value)
      @additional_opts ||= {}
      @additional_opts[key] = value
    end

    def exit_success?
      exit_success == true
    end

    def catched_error?
      !catched_error.nil?
    end

    def failure_error?
      !failure_error.nil?
    end

    def to_h
      {
        catched_error: catched_error,
        failure_error: failure_error,
        service: service.class,
        exit_success: exit_success,
        step: step,
        options: @additional_opts,
        args: args
      }
    end
  end
end