class Aquarium::Finders::MethodFinder
MethodFinder
¶ ↑
Locate methods in specified types or objects.
Constants
- CANONICAL_OPTIONS
- IGNORED_SYSTEM_METHODS
Methods we ignore by default, because users rarely want to advice them and so it makes finding what you want easier.
- METHOD_FINDER_CANONICAL_OPTIONS
- NIL_OBJECT
- RECOGNIZED_METHOD_OPTIONS
Public Class Methods
# File lib/aquarium/finders/method_finder.rb 165 def self.all_recognized_method_option_symbols 166 all = RECOGNIZED_METHOD_OPTIONS.keys.map {|key| key.intern} 167 RECOGNIZED_METHOD_OPTIONS.keys.inject(all) do |all, key| 168 all += RECOGNIZED_METHOD_OPTIONS[key].map {|value| value.intern} 169 all 170 end 171 end
# File lib/aquarium/finders/method_finder.rb 149 def self.init_method_options scope_options_set 150 return Set.new([]) if scope_options_set.nil? 151 options = [] 152 scope_options_set.each do |opt| 153 if RECOGNIZED_METHOD_OPTIONS.keys.include?(opt.to_s) 154 options << opt 155 else 156 RECOGNIZED_METHOD_OPTIONS.keys.each do |key| 157 options << key.intern if RECOGNIZED_METHOD_OPTIONS[key].include?(opt.to_s) 158 end 159 end 160 end 161 options << :instance unless (options.include?(:class) or options.include?(:singleton)) 162 Set.new(options.sort{|x,y| x.to_s <=> y.to_s}.uniq) 163 end
# File lib/aquarium/finders/method_finder.rb 173 def self.is_recognized_method_option string_or_symbol 174 sym = string_or_symbol.respond_to?(:intern) ? string_or_symbol.intern : string_or_symbol 175 all_recognized_method_option_symbols.include? sym 176 end
Public Instance Methods
Returns a Aquarium::Finders::FinderResult
, 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 method name symbols that were found. Method names, not method objects, are always returned, because we can only get method objects for instance methods if we have an instance! The keys in the “not_matched” part of the FinderResult
are the specified types and objects for which no matches were found.
The options are as follows:
Types¶ ↑
All the options supported by TypeFinder#find
.
Objects¶ ↑
One or more objects to match. Specify one or an array of values. Note: String or symbol objects will be treated as type names!
-
:objects => objects
-
:object => objects
-
:for_objects => objects
-
:for_object => objects
-
:on_objects => objects
-
:on_object => objects
-
:in_objects => objects
-
:in_object => objects
-
:within_objects => objects
-
:within_object => objects
Methods¶ ↑
One or more method names and/or regular expressions to match. Specify one or an array of values. If :all
or :all_methods
is specified, all methods in the types or objects will be matched, subject to the search options described below. That is, :all
is equivalent to the regular expression /.+/.
-
:methods => method_names_and_regexps
-
:method => method_names_and_regexps
-
:within_methods => method_names_and_regexps
-
:within_method => method_names_and_regexps
-
:calling => method_names_and_regexps
-
:invoking => method_names_and_regexps
-
:calls_to => method_names_and_regexps
-
:sending_message_to => method_names_and_regexps
-
:sending_messages_to => method_names_and_regexps
Methods Options¶ ↑
By default, the searches are restricted to public instance methods.
-
:method_options => options
-
:method_option => options
-
:restricting_methods_to => options
Note, the older, deprecated :options
synonym has been removed.
Here are the allowed “options”. Specify one or more of them. Any combination is allowed.
:public
or:public_methods
-
Search for public methods (default).
:private
or:private_methods
-
Search for private methods.
:protected
or:protected_methods
-
Search for protected methods.
:instance
or:instance_methods
-
Search for instance methods.
:class
or:class_methods
-
Search for class methods.
:singleton
or:singleton_methods
-
Search for singleton methods.
:include_system_methods
-
Also search for “system” methods like __id__ that are normally ignored (See IGNORED_SYSTEM_MEHTODS).
Note: specifying :class
when objects are specified won't work. Also, :class
, :public
, :protected
, and :private
are ignored when looking for singleton methods.
Excluded Types, Objects, or Methods¶ ↑
Exclude one or more types, objects, or methods from the match. Specify one or an array of values.
-
:exclude_methods => method_names_and_regexps
-
:exclude_method => method_names_and_regexps
-
:exclude_ancestor_methods
- Suppress “ancestor” methods.
The exclude_
prefix can be used with any of the synonyms for the other options. WARNING: the :exclude_ancestor_methods
option means that if you search for a override method foo
in a derived class and foo
is defined in the base class, you won't find it!
# File lib/aquarium/finders/method_finder.rb 93 def find options = {} 94 init_specification options, CANONICAL_OPTIONS do 95 finish_specification_initialization 96 end 97 return Aquarium::Finders::FinderResult.new if nothing_to_find? 98 types_and_objects = input_types + input_objects 99 method_names_or_regexps = input_methods 100 if method_names_or_regexps.empty? 101 not_matched = {} 102 types_and_objects.each {|t| not_matched[t] = []} 103 return Aquarium::Finders::FinderResult.new(:not_matched => not_matched) 104 end 105 result = do_find_all_by types_and_objects, method_names_or_regexps 106 unless (input_exclude_methods.nil? or input_exclude_methods.empty?) 107 result -= do_find_all_by types_and_objects, input_exclude_methods 108 end 109 result 110 end