You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by mc...@apache.org on 2014/04/21 20:41:44 UTC

svn commit: r1588958 - in /qpid/proton/trunk/proton-c/bindings/ruby/lib: qpid_proton.rb qpid_proton/filters.rb

Author: mcpierce
Date: Mon Apr 21 18:41:43 2014
New Revision: 1588958

URL: http://svn.apache.org/r1588958
Log:
NO-JIRA: Added a means for providing method hooks to the Ruby bindings.

The new module, Filters, mimics the functionality of the Ruby On Rails
filter system.

Added:
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/filters.rb
Modified:
    qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb

Modified: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb?rev=1588958&r1=1588957&r2=1588958&view=diff
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb (original)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton.rb Mon Apr 21 18:41:43 2014
@@ -26,6 +26,7 @@ require "qpid_proton/array"
 require "qpid_proton/hash"
 require "qpid_proton/exceptions"
 require "qpid_proton/exception_handling"
+require "qpid_proton/filters"
 require "qpid_proton/message_format"
 require "qpid_proton/data"
 require "qpid_proton/message"

Added: qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/filters.rb
URL: http://svn.apache.org/viewvc/qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/filters.rb?rev=1588958&view=auto
==============================================================================
--- qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/filters.rb (added)
+++ qpid/proton/trunk/proton-c/bindings/ruby/lib/qpid_proton/filters.rb Mon Apr 21 18:41:43 2014
@@ -0,0 +1,67 @@
+#
+# 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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org