Sha256: f5b6402e256a0202e34d9dfe61382bfb4a162351bc92ac571919dd71b5e360a9
Contents?: true
Size: 1.78 KB
Versions: 1
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true require_relative '../reflector' module Faker module Bot module Reflectors # Reflection object that searches all `Faker::Base` subclass methods # * Currently operates at O(n); improvements welcome. :) # # @api private # class Search < Reflector # Reflector query # # @return [String, nil] # # @api private # attr_reader :query # Initialize search reflector # # @param query [String] The search query # # @api public # def initialize(query) @query = query.downcase super end # Search through `Faker::Base` subclasses and return matching results # # @return [Hash<Class => <Array<Symbol>>] when #show_methods is truthy # # @api private # def call search_descendants_matching_query descendants_with_methods end private # Search through `Faker::Base` subclasses and store matching results # # @api private # 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 # Match a subject against the query string # # @return [Boolean] # # @api private # def query_matches?(subject) subject.to_s.match(/#{query}/i) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
faker-bot-0.5.1 | lib/faker/bot/reflectors/search.rb |