| Class | Aquarium::Finders::TypeFinder |
| In: |
lib/aquarium/finders/type_finder.rb
|
| Parent: | Object |
Locate types.
| TYPE_FINDER_CANONICAL_OPTIONS | = | { "types" => %w[type class classes module modules name names], } |
| CANONICAL_OPTIONS | = | TYPE_FINDER_CANONICAL_OPTIONS.dup |
# 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
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:
A single type, type name, name regular expression, or an array of the same. (Mixed allowed.)
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.
You can also append the suffix "_of" on any of these keys.
A single type, type name, name regular expression, or an array of the same. (Mixed allowed.) Matching types and their ancestors will be found.
You can also append the suffix "_of" on any of these keys.
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.
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 the specified type(s) from the list of matched types. Note: These excluded types won‘t appear in the FinderResult#not_matched.
You can also append the suffix "_of" on any of the "*_descendents", "*_ancestors", and "*_types" keys.
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, line 160
160: def find options = {}
161: init_specification options, CANONICAL_OPTIONS
162: result = do_find_types
163: unset_specification
164: result
165: end