Class: ADSL::Verification::InstrumentationFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/adsl/verification/instrumentation_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InstrumentationFilter

Returns a new instance of InstrumentationFilter.



5
6
7
8
9
10
# File 'lib/adsl/verification/instrumentation_filter.rb', line 5

def initialize(options = {})
  options.keys.each do |key|
    options[key] = options[key].to_s if options[key].is_a? Symbol
  end
  @options = options
end

Instance Method Details

#allow_instrumentation?(object, method_name) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/adsl/verification/instrumentation_filter.rb', line 32

def allow_instrumentation?(object, method_name)
  !applies_to? object, method_name
end

#applies_to?(object, method_name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/adsl/verification/instrumentation_filter.rb', line 12

def applies_to?(object, method_name)
  unless @options[:method_name].nil?
    return false unless @options[:method_name] === method_name.to_s
  end
  unless @options[:method_owner].nil?
    return false if object.is_a?(Fixnum) or object.is_a?(Symbol)
    method = object.singleton_class.instance_method method_name
    return false unless method.owner == @options[:method_owner]
  end
  unless @options[:if].nil?
    subcondition = InstrumentationFilter.new(@options[:if])
    return false if subcondition.applies_to? object, method_name
  end
  unless @options[:unless].nil?
    subcondition = InstrumentationFilter.new(@options[:unless])
    return false unless subcondition.applies_to? object, method_name
  end
  true
end