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.deferred_logic_results(item)
      if value
        new_matcher = MethodMatcher.new(value)
        new_matcher.match?(method)
      end
    when DeferredOption
      value = aspect.options[item.key]
      if value
        new_matcher = MethodMatcher.new(value)
        new_matcher.match?(method)
      end
    end
  end
end

#to_sObject



39
40
41
# File 'lib/aspector/method_matcher.rb', line 39

def to_s
  @match_data.map(&:inspect).join(', ')
end

#use_deferred_logic?(logic) ⇒ Boolean

Returns:

  • (Boolean)


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

def use_deferred_logic?(logic)
  @match_data.detect do |item|
    logic == item
  end
end