Sha256: 606b9475d4031c5d9affb6277b149526dc444a824b544a2e275773bf2bb97cc9

Contents?: true

Size: 953 Bytes

Versions: 5

Compression:

Stored size: 953 Bytes

Contents

# frozen_string_literal: true

require "isolator/adapters/base"

module Isolator
  # Builds adapter from provided params
  module AdapterBuilder
    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)
        self.details_message = options[:details_message] if options.key?(:details_message)
      end

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

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

      base.prepend mod
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
isolator-0.8.0 lib/isolator/adapter_builder.rb
isolator-0.7.0 lib/isolator/adapter_builder.rb
isolator-0.6.2 lib/isolator/adapter_builder.rb
isolator-0.6.1 lib/isolator/adapter_builder.rb
isolator-0.6.0 lib/isolator/adapter_builder.rb