Class: FactoryBotRails::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/factory_bot_rails/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Generator

Returns a new instance of Generator.



7
8
9
10
11
12
13
# File 'lib/factory_bot_rails/generator.rb', line 7

def initialize(config)
  @generators = if config.respond_to?(:app_generators)
                  config.app_generators
                else
                  config.generators
                end
end

Instance Method Details

#factory_bot_disabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/factory_bot_rails/generator.rb', line 35

def factory_bot_disabled?
  rails_options[:factory_bot] == false
end

#generatorObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/factory_bot_rails/generator.rb', line 19

def generator
  if factory_bot_disabled?
    Generators::NullGenerator
  else
    if test_framework == :rspec
      Generators::RSpecGenerator
    else
      Generators::NonRSpecGenerator
    end
  end
end

#rails_optionsObject



39
40
41
# File 'lib/factory_bot_rails/generator.rb', line 39

def rails_options
  @generators.options[:rails]
end

#runObject



15
16
17
# File 'lib/factory_bot_rails/generator.rb', line 15

def run
  generator.new(@generators).run
end

#test_frameworkObject



31
32
33
# File 'lib/factory_bot_rails/generator.rb', line 31

def test_framework
  rails_options[:test_framework]
end