Class: Aquarium::Finders::TypeFinder
- Includes:
- Utils::ArrayUtils, Utils::OptionsUtils, Utils::TypeUtils
- Defined in:
- lib/aquarium/finders/type_finder.rb
Overview
TypeFinder
Locate types.
Defined Under Namespace
Classes: TypeFinderResult
Constant Summary collapse
- TYPE_FINDER_CANONICAL_OPTIONS =
{ "types" => %w[type class classes module modules name names], }
- CANONICAL_OPTIONS =
TYPE_FINDER_CANONICAL_OPTIONS.dup
Instance Attribute Summary
Attributes included from Utils::OptionsUtils
Class Method Summary collapse
Instance Method Summary collapse
-
#find(options = {}) ⇒ Object
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.
Methods included from Utils::OptionsUtils
append_features, #hashify, #init_specification, universal_options, universal_prepositions, #validate_options
Methods included from Utils::ArrayUtils
#make_array, make_array, #strip_array_nils, strip_array_nils
Methods included from Utils::SetUtils
#make_set, #strip_set_nils, strip_set_nils
Methods included from Utils::TypeUtils
Class Method Details
.add_ancestors_descendents_and_nested_option_variants_for(option, options_hash) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/aquarium/finders/type_finder.rb', line 26 def self.add_ancestors_descendents_and_nested_option_variants_for option, all_variants = [option].dup %w[descendents ancestors nested_types].each do |suffix| ["#{option}_and_#{suffix}"] = all_variants.inject([]) do |memo, x| memo << "#{x}_and_#{suffix}" << "#{x}_and_#{suffix}_of" end end ["#{option}_and_nested_types"] += all_variants.map {|x| "#{x}_and_nested"} end |
Instance Method Details
#find(options = {}) ⇒ Object
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, 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>i.e.</i>, as if you wrote <tt>/^.*#{regexp}.*$/.</tt>
A subexp before the first "::"::
It behaves as <tt>/^.*#{subexp}::.../</tt>, meaning that the end of "subexp"
must be followed by "::".
A subexp after the last "::"::
It behaves as <tt>/...::#{subexp}$/</tt>, meaning that the beginning of "subexp"
must immediately follow a "::".
For a subexp between two "::"::
It behaves as <tt>/...::#{subexp}::.../</tt>, 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"
159 160 161 162 163 164 |
# File 'lib/aquarium/finders/type_finder.rb', line 159 def find = {} init_specification , CANONICAL_OPTIONS result = do_find_types unset_specification result end |