Module: Aquarium::Aspects::ExclusionHandler

Includes:
Utils::HashUtils
Included in:
Aspect, Pointcut
Defined in:
lib/aquarium/aspects/exclusion_handler.rb

Overview

Defines methods shared by several classes that take :exclude_* arguments.

Instance Method Summary collapse

Methods included from Utils::HashUtils

#make_hash, #strip_nil_keys

Methods included from Utils::ArrayUtils

#make_array, make_array, #strip_array_nils, strip_array_nils

Instance Method Details

#all_excluded_pointcutsObject



28
29
30
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 28

def all_excluded_pointcuts
  @all_excluded_pointcuts ||= @specification[:exclude_pointcuts]
end

#is_excluded_join_point?(jp) ⇒ Boolean

Using @specification.include?(jp) doesn’t always work correctly (it probably uses equal?())!

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 33

def is_excluded_join_point? jp
  return false if @specification[:exclude_join_points].nil?
  @specification[:exclude_join_points].find {|jp2| jp2 == jp || jp2.eql?(jp)}
end

#is_excluded_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 55

def is_excluded_method? method
  is_explicitly_excluded_method?(method) or matches_excluded_method_regex?(method)
end

#is_excluded_pointcut?(jp) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 14

def is_excluded_pointcut? jp
  return false if all_excluded_pointcuts.empty?
  all_excluded_pointcuts.find do |pc|
    pc.join_points_matched.find do |jp2|
      jp2 == jp || jp2.eql?(jp)
    end
  end
end

#is_excluded_type_or_object?(type_or_object) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 38

def is_excluded_type_or_object? type_or_object
  unless @specification[:exclude_objects].nil?
    return true if @specification[:exclude_objects].include?(type_or_object)
  end
  unless @specification[:exclude_types_calculated].nil?
    return true if @specification[:exclude_types_calculated].find do |t|
      case t
      when String then type_or_object.name.eql?(t)
      when Symbol then type_or_object.name.eql?(t.to_s)
      when Regexp then type_or_object.name =~ t
      else type_or_object == t
      end
    end
  end
  false
end

#is_explicitly_excluded_method?(method) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 59

def is_explicitly_excluded_method? method
  return false if @specification[:exclude_methods].nil?
  @specification[:exclude_methods].include? method
end

#join_point_excluded?(jp) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 10

def join_point_excluded? jp
  is_excluded_pointcut?(jp) or is_excluded_join_point?(jp) or is_excluded_type_or_object?(jp.type_or_object) or is_excluded_method?(jp.method_name)
end

#matches_excluded_method_regex?(method) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 64

def matches_excluded_method_regex? method
  return false if @specification[:exclude_methods].nil?
  regexs = @specification[:exclude_methods].find_all {|s| s.kind_of? Regexp}
  return false if regexs.empty?
  regexs.find {|re| method.to_s =~ re}          
end

#set_calculated_excluded_pointcuts(excluded_pointcuts) ⇒ Object



23
24
25
26
# File 'lib/aquarium/aspects/exclusion_handler.rb', line 23

def set_calculated_excluded_pointcuts excluded_pointcuts
  @calculated_excluded_pointcuts = excluded_pointcuts
  @all_excluded_pointcuts = @specification[:exclude_pointcuts] | Set.new(@calculated_excluded_pointcuts)
end