class Aquarium::Finders::TypeFinder

TypeFinder

Locate types.

Constants

CANONICAL_OPTIONS
TYPE_FINDER_CANONICAL_OPTIONS

Public Class Methods

add_ancestors_descendents_and_nested_option_variants_for(option, options_hash) click to toggle source
   # File lib/aquarium/finders/type_finder.rb
26 def self.add_ancestors_descendents_and_nested_option_variants_for option, options_hash
27   all_variants = options_hash[option].dup
28   %w[descendents ancestors nested_types].each do |suffix|
29     options_hash["#{option}_and_#{suffix}"] = all_variants.inject([]) do |memo, x|
30       memo << "#{x}_and_#{suffix}" << "#{x}_and_#{suffix}_of"
31     end
32   end
33   options_hash["#{option}_and_nested_types"] += all_variants.map {|x| "#{x}_and_nested"}
34 end

Public Instance Methods

find(options = {}) click to toggle source

Returns a TypeFinder::TypeFinderResult, where the “matched” keys are the input types, type names, and/or regular expressions, and objects for which matches were found and the corresponding values are the class constant or variable pointcuts that were found. The keys in the “not_matched” part of the result are the specified types and objects for which no matches were found.

The options are as follows:

Types

A single type, type name, name regular expression, or an array of the same. (Mixed allowed.)

  • :types => types_and_type_names_and_regexps

  • :names => types_and_type_names_and_regexps

  • :type => types_and_type_names_and_regexps

  • :name => types_and_type_names_and_regexps

Types and Descendents

A single type, type name, name regular expression, or an array of the same. (Mixed allowed.) Matching types and their descendents will be found. A type that includes a module is considered a descendent, since the module would show up in that type's ancestors.

  • :types_and_descendents => types_and_type_names_and_regexps

  • :names_and_descendents => types_and_type_names_and_regexps

  • :type_and_descendents => types_and_type_names_and_regexps

  • :name_and_descendents => types_and_type_names_and_regexps

You can also append the suffix “_of” on any of these keys.

Types and Ancestors

A single type, type name, name regular expression, or an array of the same. (Mixed allowed.) Matching types and their ancestors will be found.

  • :types_and_ancestors => types_and_type_names_and_regexps

  • :names_and_ancestors => types_and_type_names_and_regexps

  • :type_and_ancestors => types_and_type_names_and_regexps

  • :name_and_ancestors => types_and_type_names_and_regexps

You can also append the suffix “_of” on any of these keys.

Types and Nested Types

A single type, type name, name regular expression, or an array of the same. (Mixed allowed.) Matching types and any types nested within them will be found.

  • :types_and_nested_types => types_and_type_names_and_regexps

  • :names_and_nested_types => types_and_type_names_and_regexps

  • :type_and_nested_types => types_and_type_names_and_regexps

  • :name_and_nested_types => types_and_type_names_and_regexps

  • :types_and_nested => types_and_type_names_and_regexps

  • :names_and_nested => types_and_type_names_and_regexps

  • :type_and_nested => types_and_type_names_and_regexps

  • :name_and_nested => types_and_type_names_and_regexps

You can also append the suffix “_of” on any of the “*_types” keys.

Note: This option will also match Class, Module, <i>etc.</>, so use with caution!

To get both descendents and ancestors, use both options with the same type specification.

Exclude Types

Exclude the specified type(s) from the list of matched types. Note: These excluded types won't appear in the FinderResult#not_matched.

  • :exclude_type => types_and_type_names_and_regexps

  • :exclude_types => types_and_type_names_and_regexps

  • :exclude_name => types_and_type_names_and_regexps

  • :exclude_names => types_and_type_names_and_regexps

  • :exclude_types_and_descendents => types_and_type_names_and_regexps

  • :exclude_names_and_descendents => types_and_type_names_and_regexps

  • :exclude_type_and_descendents => types_and_type_names_and_regexps

  • :exclude_name_and_descendents => types_and_type_names_and_regexps

  • :exclude_types_and_ancestors => types_and_type_names_and_regexps

  • :exclude_names_and_ancestors => types_and_type_names_and_regexps

  • :exclude_type_and_ancestors => types_and_type_names_and_regexps

  • :exclude_name_and_ancestors => types_and_type_names_and_regexps

  • :exclude_types_and_nested_types => types_and_type_names_and_regexps

  • :exclude_names_and_nested_types => types_and_type_names_and_regexps

  • :exclude_type_and_nested_types => types_and_type_names_and_regexps

  • :exclude_name_and_nested_types => types_and_type_names_and_regexps

  • :exclude_types_and_nested => types_and_type_names_and_regexps

  • :exclude_names_and_nested => types_and_type_names_and_regexps

  • :exclude_type_and_nested => types_and_type_names_and_regexps

  • :exclude_name_and_nested => types_and_type_names_and_regexps

You can also append the suffix “_of” on any of the “*_descendents”, “*_ancestors”, and “*_types” keys.

Namespaces (Modules) and Regular Expressions

Because of the special sigificance of the module (“namespace”) separator “::”, special rules for the regular expressions apply. Normally, you can just use the “*_and_nested_types” or “*_and_nested” to match enclosed types, but if you want to be selective, note the following. First, assume that “subexp” is a “sub regular expression” that results if you split on the separator “::”.

A full regexp with no “::”

Allow partial matches, i.e., as if you wrote /^.*#{regexp}.*$/.

A subexp before the first “::”

It behaves as /^.*#{subexp}::.../, meaning that the end of “subexp” must be followed by “::”.

A subexp after the last “::”

It behaves as /...::#{subexp}$/, meaning that the beginning of “subexp” must immediately follow a “::”.

For a subexp between two “::”

It behaves as /...::#{subexp}::.../, meaning that the subexp must match the whole name between the “::” exactly.

Note: a common idiom in aspects is to include descendents of a type, but not the type itself. You can do as in the following example:

<tt>... :type_and_descendents => "Foo", :exclude_type => "Foo"
    # File lib/aquarium/finders/type_finder.rb
159 def find options = {}
160   init_specification options, CANONICAL_OPTIONS
161   result = do_find_types
162   unset_specification
163   result 
164 end