Class Aquarium::Finders::TypeFinder
In: lib/aquarium/finders/type_finder.rb
Parent: Object

TypeFinder

Locate types.

Methods

Included Modules

Aquarium::Utils::ArrayUtils Aquarium::Utils::TypeUtils Aquarium::Utils::OptionsUtils

Classes and Modules

Class Aquarium::Finders::TypeFinder::TypeFinderResult

Constants

TYPE_FINDER_CANONICAL_OPTIONS = { "types" => %w[type class classes module modules name names], }
CANONICAL_OPTIONS = TYPE_FINDER_CANONICAL_OPTIONS.dup

Public Class methods

[Source]

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

Public Instance methods

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"

[Source]

     # File lib/aquarium/finders/type_finder.rb, line 160
160:       def find options = {}
161:         init_specification options, CANONICAL_OPTIONS
162:         result = do_find_types
163:         unset_specification
164:         result 
165:       end

[Validate]