class Yoda::Store::Query::FindMethod

Public Instance Methods

find(namespace, method_name, visibility: nil) click to toggle source

@param namespace [Objects::Namespace] @param method_name [String, Regexp] @param visibility [Array<Symbol>, nil] @return [Objects::MethodObject, nil]

# File lib/yoda/store/query/find_method.rb, line 9
def find(namespace, method_name, visibility: nil)
  lazy_select(namespace, method_name, visibility: visibility).first
end
select(namespace, method_name, visibility: nil) click to toggle source

@param namespace [Objects::Namespace] @param method_name [String, Regexp] @param visibility [Array<Symbol>, nil] @return [Array<Objects::MethodObject>]

# File lib/yoda/store/query/find_method.rb, line 17
def select(namespace, method_name, visibility: nil)
  lazy_select(namespace, method_name, visibility: nil).to_a
end

Private Instance Methods

lazy_select(namespace, expected, visibility: nil) click to toggle source

@param namespace [Objects::Namespace] @param expected [String, Regexp] @param visibility [Array<Symbol>, nil] @return [Enumerator<Objects::MethodObject>]

# File lib/yoda/store/query/find_method.rb, line 27
def lazy_select(namespace, expected, visibility: nil)
  visibility ||=  %i(public private protected)
  Enumerator.new do |yielder|
    Associators::AssociateMethods.new(registry).associate(namespace).each do |method|
      if match_name?(method.name, expected) && visibility.include?(method.visibility)
        yielder << method
      end
    end
  end
end
match_name?(name, expected_name_or_pattern) click to toggle source

@param name [String] @param expected_name_or_pattern [String, Regexp] @return [true, false]

# File lib/yoda/store/query/find_method.rb, line 41
def match_name?(name, expected_name_or_pattern)
  case expected_name_or_pattern
  when String
    name == expected_name_or_pattern
  when Regexp
    name.match?(expected_name_or_pattern)
  else
    fail ArgumentError, expected_name_or_pattern
  end
end