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
# File 'lib/factory_bot_rails/generator.rb', line 7

def initialize(config)
  @generators = config.app_generators
end

Instance Method Details

#factory_bot_disabled?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/factory_bot_rails/generator.rb', line 29

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

#generatorObject


15
16
17
18
19
20
21
22
23
# File 'lib/factory_bot_rails/generator.rb', line 15

def generator
  return Generators::NullGenerator if factory_bot_disabled?

  if test_framework == :rspec
    Generators::RSpecGenerator
  else
    Generators::NonRSpecGenerator
  end
end

#rails_optionsObject


33
34
35
# File 'lib/factory_bot_rails/generator.rb', line 33

def rails_options
  @generators.options[:rails]
end

#runObject


11
12
13
# File 'lib/factory_bot_rails/generator.rb', line 11

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

#test_frameworkObject


25
26
27
# File 'lib/factory_bot_rails/generator.rb', line 25

def test_framework
  rails_options[:test_framework]
end