File: generator.rb

package info (click to toggle)
ruby-factory-bot-rails 6.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ruby: 635; makefile: 6; sh: 4
file content (37 lines) | stat: -rw-r--r-- 791 bytes parent folder | download | duplicates (4)
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
require "factory_bot_rails/generators/rspec_generator"
require "factory_bot_rails/generators/non_rspec_generator"
require "factory_bot_rails/generators/null_generator"

module FactoryBotRails
  class Generator
    def initialize(config)
      @generators = config.app_generators
    end

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

    def generator
      return Generators::NullGenerator if factory_bot_disabled?

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

    def test_framework
      rails_options[:test_framework]
    end

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

    def rails_options
      @generators.options[:rails]
    end
  end
end