Module: Isolator::AdapterBuilder

Defined in:
lib/isolator/adapter_builder.rb

Overview

Builds adapter from provided params

Class Method Summary collapse

Class Method Details

.add_patch_method(adapter, base, method_name) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/isolator/adapter_builder.rb', line 21

def self.add_patch_method(adapter, base, method_name)
  mod = Module.new do
    define_method method_name do |*args, &block|
      adapter.notify(caller, *args)
      super(*args, &block)
    end
  end

  base.prepend mod
end

.call(target: nil, method_name: nil, **options) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/isolator/adapter_builder.rb', line 8

def self.call(target: nil, method_name: nil, **options)
  adapter = Module.new do
    extend Isolator::Adapters::Base

    self.exception_class = options[:exception_class] if options.key?(:exception_class)
    self.exception_message = options[:exception_message] if options.key?(:exception_message)
  end

  add_patch_method(adapter, target, method_name) if
    target && method_name
  adapter
end