Sha256: a7e34b00f8d7d7e6f3d32cf53b737e6529a5a4ada61b11fa43bb5a33bc0483e0

Contents?: true

Size: 1.89 KB

Versions: 9

Compression:

Stored size: 1.89 KB

Contents

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

module Qpid

  module Proton

    module Filters

      def self.included(base)
        base.class_eval do
          extend ClassMethods
        end
      end

      module ClassMethods

        def method_added(method_name)
          @@hooked_methods ||= []
          return if @@hooked_methods.include?(method_name)
          @@hooked_methods << method_name
          hooks = @@before_hooks[method_name]
          return if hooks.nil?
          orig_method = instance_method(method_name)
          define_method(method_name) do |*args, &block|
            hooks = @@before_hooks[method_name]
            hooks.each do |hook|
              method(hook).call
            end

            orig_method.bind(self).call(*args, &block)
          end
        end

        def call_before(before_method, *methods)
          @@before_hooks ||= {}
          methods.each do |method|
            hooks = @@before_hooks[method] || []
            raise "Repeat filter: #{before_method}" if hooks.include? before_method
            hooks << before_method
            @@before_hooks[method] = hooks
          end
        end

      end

    end

  end

end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mqlight-1.0.2015020300.beta-x86_64-darwin-15 lib/qpid_proton/filters.rb
mqlight-1.0.2015020300.beta-x86_64-linux lib/qpid_proton/filters.rb
mqlight-1.0.2015020300.beta-x86_64-darwin-13 lib/qpid_proton/filters.rb
mqlight-1.0.2014120914.beta-x86_64-darwin-13 lib/qpid_proton/filters.rb
mqlight-1.0.2014120914.beta-x86_64-linux lib/qpid_proton/filters.rb
mqlight-1.0.2014120516.beta-x86_64-linux lib/qpid_proton/filters.rb
mqlight-1.0.2014120423.beta-x86_64-linux lib/qpid_proton/filters.rb
qpid_proton-0.8 lib/qpid_proton/filters.rb
qpid_proton-0.7.1 lib/qpid_proton/filters.rb