Class Aquarium::Finders::MethodFinder
In: lib/aquarium/finders/method_finder.rb
Parent: Object

MethodFinder

Locate methods in specified types or objects.

Methods

Included Modules

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

Constants

NIL_OBJECT = MethodFinder.new unless const_defined?(:NIL_OBJECT)
METHOD_FINDER_CANONICAL_OPTIONS = { "objects" => %w[object for_object for_objects on_object on_objects in_object in_objects within_object within_objects], "methods" => %w[method within_method within_methods calling invoking invocations_of calls_to sending_message_to sending_messages_to], "method_options" => %w[options method_option restricting_methods_to]
CANONICAL_OPTIONS = METHOD_FINDER_CANONICAL_OPTIONS.merge(Aquarium::Finders::TypeFinder::TYPE_FINDER_CANONICAL_OPTIONS)
RECOGNIZED_METHOD_OPTIONS = { "all" => %w[all_methods], "public" => %w[public_methods], "private" => %w[private_methods], "protected" => %w[protected_methods], "instance" => %w[instance_methods], "class" => %w[class_methods], "singleton" => %w[singleton_methods], "exclude_ancestor_methods" => %w[exclude_ancestors exclude_ancestors_methods suppress_ancestors suppress_ancestor_methods suppress_ancestors_methods], "include_system_methods" => %w[include_all_system_methods]
IGNORED_SYSTEM_METHODS = [/^__/]   Methods we ignore by default, because users rarely want to advice them and so it makes finding what you want easier.

Public Class methods

[Source]

     # File lib/aquarium/finders/method_finder.rb, line 167
167:       def self.all_recognized_method_option_symbols
168:         all = RECOGNIZED_METHOD_OPTIONS.keys.map {|key| key.intern}
169:         RECOGNIZED_METHOD_OPTIONS.keys.inject(all) do |all, key|
170:           all += RECOGNIZED_METHOD_OPTIONS[key].map {|value| value.intern}
171:           all
172:         end
173:       end

[Source]

     # File lib/aquarium/finders/method_finder.rb, line 151
151:       def self.init_method_options scope_options_set
152:         return Set.new([]) if scope_options_set.nil?
153:         options = []
154:         scope_options_set.each do |opt|
155:           if RECOGNIZED_METHOD_OPTIONS.keys.include?(opt.to_s)
156:             options << opt
157:           else
158:             RECOGNIZED_METHOD_OPTIONS.keys.each do |key|
159:               options << key.intern if RECOGNIZED_METHOD_OPTIONS[key].include?(opt.to_s)
160:             end
161:           end
162:         end
163:         options << :instance unless (options.include?(:class) or options.include?(:singleton))
164:         Set.new(options.sort.uniq)
165:       end

[Source]

     # File lib/aquarium/finders/method_finder.rb, line 175
175:       def self.is_recognized_method_option string_or_symbol
176:         sym = string_or_symbol.respond_to?(:intern) ? string_or_symbol.intern : string_or_symbol
177:         all_recognized_method_option_symbols.include? sym
178:       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
  • :options => options
  • :restricting_methods_to => options

Note, the :options synonym is deprecated.

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!

[Source]

     # File lib/aquarium/finders/method_finder.rb, line 94
 94:       def find options = {}
 95:         init_specification options, CANONICAL_OPTIONS do
 96:           finish_specification_initialization 
 97:         end
 98:         warn_if_deprecated_options_used options
 99:         return Aquarium::Finders::FinderResult.new if nothing_to_find?
100:         types_and_objects = input_types + input_objects
101:         method_names_or_regexps = input_methods
102:         if method_names_or_regexps.empty?
103:           not_matched = {}
104:           types_and_objects.each {|t| not_matched[t] = []}
105:           return Aquarium::Finders::FinderResult.new(:not_matched => not_matched)
106:         end
107:         result = do_find_all_by types_and_objects, method_names_or_regexps
108:         unless (input_exclude_methods.nil? or input_exclude_methods.empty?)
109:           result -= do_find_all_by types_and_objects, input_exclude_methods
110:         end
111:         result
112:       end

[Validate]