Sha256: 104c3105c9f13cd209fee5dc24bfbd08bd1f671ebe4e5a742e13cbba4b7b8012

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

module Aspect4r
  module Model
    class MethodMatcher
      def initialize *match_data
        @match_data = match_data

        # Performance improvement ideas: 
        #  if there is only one item in match_data, generate simplified match? method on the fly
        #  Seems this does not help much
        #
        # if match_data.size == 1
        #   first_item = match_data.first
        #   eigen_class = class << self; self; end
        # 
        #   if first_item.is_a? String
        #     eigen_class.send :define_method, :match? do |method|
        #       method == first_item
        #     end
        #   elsif first_item.is_a? Regexp
        #     eigen_class.send :define_method, :match? do |method|
        #       method =~ first_item
        #     end
        #   else
        #     eigen_class.send :define_method, :match? do |method|
        #       false
        #     end
        #   end
        # end
      end

      def match? method
        @match_data.detect do |item|
          (item.is_a? String and item == method) or
          (item.is_a? Regexp and item =~ method)
        end
      end
      
      def to_s
        @match_data.map {|item| item.inspect }.join ", "
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aspect4r-0.10.0 lib/aspect4r/model/method_matcher.rb
aspect4r-0.9.1 lib/aspect4r/model/method_matcher.rb