File: generators.rb

package info (click to toggle)
ruby-faker 3.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,596 kB
  • sloc: ruby: 20,656; sh: 6; makefile: 6
file content (46 lines) | stat: -rw-r--r-- 812 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'benchmark/ips'
require 'faker'

def generators
  constants.flat_map do |klass|
    subclass_methods(klass)
  end
end

def constants
  Faker.constants.delete_if do |subclass|
    %i[
      Base
      Cat
      Char
      Base58
      Config
      Date
      Deprecator
      Dog
      Religion
      Time
      VERSION
    ].include?(subclass)
  end.sort
end

def subclass_methods(subclass)
  klass = Faker.const_get(subclass)

  public_methods = klass.public_methods(false) - Faker::Base.public_methods(false)

  public_methods.sort.map do |method|
    [klass, method]
  end
end

all_generators = generators

Benchmark.ips do |x|
  x.report("Number of generators: #{all_generators.count}") do
    all_generators.each { |klass, generator| klass.send(generator) }
  end
end