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

all_recognized_method_option_symbols() click to toggle source
# File lib/aquarium/finders/method_finder.rb, line 165
def self.all_recognized_method_option_symbols
  all = RECOGNIZED_METHOD_OPTIONS.keys.map {|key| key.intern}
  RECOGNIZED_METHOD_OPTIONS.keys.inject(all) do |all, key|
    all += RECOGNIZED_METHOD_OPTIONS[key].map {|value| value.intern}
    all
  end
end
init_method_options(scope_options_set) click to toggle source
# File lib/aquarium/finders/method_finder.rb, line 149
def self.init_method_options scope_options_set
  return Set.new([]) if scope_options_set.nil?
  options = []
  scope_options_set.each do |opt|
    if RECOGNIZED_METHOD_OPTIONS.keys.include?(opt.to_s)
      options << opt
    else
      RECOGNIZED_METHOD_OPTIONS.keys.each do |key|
        options << key.intern if RECOGNIZED_METHOD_OPTIONS[key].include?(opt.to_s)
      end
    end
  end
  options << :instance unless (options.include?(:class) or options.include?(:singleton))
  Set.new(options.sort{|x,y| x.to_s <=> y.to_s}.uniq)
end
is_recognized_method_option(string_or_symbol) click to toggle source
# File lib/aquarium/finders/method_finder.rb, line 173
def self.is_recognized_method_option string_or_symbol
  sym = string_or_symbol.respond_to?(:intern) ? string_or_symbol.intern : string_or_symbol
  all_recognized_method_option_symbols.include? sym
end

Public Instance Methods

find(options = {}) click to toggle source

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 Aquarium::Finders::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, line 93
def find options = {}
  init_specification options, CANONICAL_OPTIONS do
    finish_specification_initialization 
  end
  return Aquarium::Finders::FinderResult.new if nothing_to_find?
  types_and_objects = input_types + input_objects
  method_names_or_regexps = input_methods
  if method_names_or_regexps.empty?
    not_matched = {}
    types_and_objects.each {|t| not_matched[t] = []}
    return Aquarium::Finders::FinderResult.new(:not_matched => not_matched)
  end
  result = do_find_all_by types_and_objects, method_names_or_regexps
  unless (input_exclude_methods.nil? or input_exclude_methods.empty?)
    result -= do_find_all_by types_and_objects, input_exclude_methods
  end
  result
end