Module: Aquarium::Aspects::DefaultObjectsHandler

Includes:
Utils::ArrayUtils
Included in:
Aspect, Pointcut
Defined in:
lib/aquarium/aspects/default_objects_handler.rb

Overview

Some classes support a :default_objects option and use it if no type or object is specified. In other words, the :default_objects option is ignored if :types or :objects is present. This module handles this behavior for all the classes that include it. These classes are assumed to have @specification defined with keys :default_objects, :types, and :objects.

Instance Method Summary collapse

Methods included from Utils::ArrayUtils

#make_array, make_array, #strip_array_nils, strip_array_nils

Instance Method Details

#default_objects_givenObject



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

def default_objects_given
  if @default_objects.nil?
    ary1 = make_array(@specification[:default_objects])
    ary2 = make_array(@specification[:default_object])
    @default_objects = ary1 + ary2
  end
  @default_objects
end

#default_objects_given?Boolean

Returns:

  • (Boolean)


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

def default_objects_given?
  not default_objects_given.empty?
end

#use_default_objects_if_definedObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/aquarium/aspects/default_objects_handler.rb', line 28

def use_default_objects_if_defined
  return unless default_objects_given?
  default_objects_given.each do |object|
    if (object.kind_of?(Class) || object.kind_of?(Module))
      @specification[:types] ||= []
      @specification[:types] << object
    else
      @specification[:objects] ||= []
      @specification[:objects] << object
    end
  end
end