Class: Aspector::MethodMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/aspector/method_matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(*match_data) ⇒ MethodMatcher

Returns a new instance of MethodMatcher.



3
4
5
6
# File 'lib/aspector/method_matcher.rb', line 3

def initialize *match_data
  @match_data = match_data
  @match_data.flatten!
end

Instance Method Details

#match?(method, aspect = nil) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/aspector/method_matcher.rb', line 8

def match? method, aspect = nil
  @match_data.detect do |item|
    case item
    when String
      item == method
    when Regexp
      item =~ method
    when Symbol
      item.to_s == method
    when DeferredLogic
      value = aspect.aop_deferred_logic_results(item)
      if value
        new_matcher = MethodMatcher.new(value)
        new_matcher.match?(method)
      end
    when DeferredOption
      value = aspect.send(:aop_options)[item.key]
      if value
        new_matcher = MethodMatcher.new(value)
        new_matcher.match?(method)
      end
    end
  end
end

#to_sObject



33
34
35
# File 'lib/aspector/method_matcher.rb', line 33

def to_s
  @match_data.map {|item| item.inspect }.join ", "
end