Sha256: f140238de923688d60e8fc3829b923d9e80f34aaec2b5be3060636725d650226

Contents?: true

Size: 736 Bytes

Versions: 8

Compression:

Stored size: 736 Bytes

Contents

module MagicLamp
  module Callbacks
    attr_accessor :configuration

    def initialize(configuration)
      self.configuration = configuration
    end

    def execute_before_each_callback
      execute_callback(:before)
    end

    def execute_after_each_callback
      execute_callback(:after)
    end

    def execute_callbacks_around(&block)
      if block.nil?
        raise ArgumentError, "#{self.class.name}##{__method__} requires a block"
      end

      execute_before_each_callback
      value = block.call
      execute_after_each_callback
      value
    end

    private

    def execute_callback(type)
      callback = configuration.send("#{type}_each_proc")
      callback.call unless callback.nil?
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
magic_lamp-1.8.1 lib/magic_lamp/callbacks.rb
magic_lamp-1.8.0 lib/magic_lamp/callbacks.rb
magic_lamp-1.7.0 lib/magic_lamp/callbacks.rb
magic_lamp-1.6.2 lib/magic_lamp/callbacks.rb
magic_lamp-1.6.1 lib/magic_lamp/callbacks.rb
magic_lamp-1.6.0 lib/magic_lamp/callbacks.rb
magic_lamp-1.5.2 lib/magic_lamp/callbacks.rb
magic_lamp-1.5.1 lib/magic_lamp/callbacks.rb