Module: Bigcommerce::Multitrap::PatchedTrap

Defined in:
lib/bigcommerce/multitrap/patched_trap.rb

Class Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



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
# File 'lib/bigcommerce/multitrap/patched_trap.rb', line 6

def self.included(mod)
  original_trap = Signal.method(:trap)

  mod.instance_eval do
    define_method(:trap) do |*args, &block|
      if args.size < 1
        if Bigcommerce::Multitrap.rbx?
          raise ArgumentError, "method 'trap': given 0, expected 2"
        elsif Bigcommerce::Multitrap.jruby?
          raise ArgumentError, "wrong number of arguments (0 for 1)"
        else
          raise ArgumentError, "wrong number of arguments (0 for 1..2)"
        end
      end

      if block.nil?
        if Bigcommerce::Multitrap.rbx? && !args[1].respond_to?(:call)
          raise ArgumentError, "Handler must respond to #call (was #{args[1].class})"
        elsif args[1].nil?
          raise ArgumentError, 'tried to create Proc object without a block'
        end
      end

      Bigcommerce::Multitrap::Trap.trap(original_trap, *args, &block)
    end
  end
end