class Faker::Bot::Reflectors::Search
Reflection object that searches all `Faker::Base` subclass methods
* Currently operates at O(n); improvements welcome. :)
@api private
Attributes
query[R]
Public Class Methods
new(query)
click to toggle source
Initialize search reflector
@param query [String] The search query
@api public
Calls superclass method
Faker::Bot::Reflector::new
# File lib/faker/bot/reflectors/search.rb, line 28 def initialize(query) @query = query.downcase super end
Public Instance Methods
call()
click to toggle source
Search
through `Faker::Base` subclasses and return matching results
@return [Hash<Class => <Array<Symbol>>] when show_methods is truthy
@api private
# File lib/faker/bot/reflectors/search.rb, line 40 def call search_descendants_matching_query descendants_with_methods end
Private Instance Methods
query_matches?(subject)
click to toggle source
Match a subject against the query string
@return [Boolean]
@api private
# File lib/faker/bot/reflectors/search.rb, line 71 def query_matches?(subject) subject.to_s.match(/#{query}/i) end
search_descendants_matching_query()
click to toggle source
Search
through `Faker::Base` subclasses and store matching results
@api private
# File lib/faker/bot/reflectors/search.rb, line 51 def search_descendants_matching_query faker_descendants.each do |descendant| methods = descendant.my_singleton_methods if query_matches?(descendant) store(descendant, methods) else store( descendant, methods.select { |method| query_matches?(method) } ) end end end