Module: Faker::FakerMethodsDelegator

Included in:
Fake
Defined in:
lib/fake.rb

Defined Under Namespace

Modules: ClassDelegationMethods

Class Method Summary collapse

Class Method Details

.faker_method_modulesObject



8
9
10
11
12
# File 'lib/fake.rb', line 8

def faker_method_modules
  Faker.constants
    .map{|c| Faker.const_get(c)}
    .select{|const| const.is_a?(Class) && const.superclass == Faker::Base}
end

.faker_methods_hashObject



14
15
16
17
18
19
20
21
22
# File 'lib/fake.rb', line 14

def faker_methods_hash
  Hash[
    *faker_method_modules.map do |faker_mod|
      (faker_mod.methods - Faker::Base.methods).map do |method_name|
        [method_name, faker_mod.method(method_name)]
      end
    end.flatten
  ]
end

.included(base) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/fake.rb', line 25

def self.included(base)
  base.class_eval do
    @faker_methods_hash = FakerMethodsDelegator.faker_methods_hash
    class << self
      include ClassDelegationMethods
      alias_method :respond_to_without_faker_methods?, :respond_to?
      alias_method :respond_to?, :respond_to_with_faker_methods?
    end
  end
end