class FactoryBot::Generators::ModelGenerator
Public Instance Methods
create_fixture_file()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 28 def create_fixture_file if File.exist?(factories_file) insert_factory_into_existing_file else create_factory_file end end
Private Instance Methods
create_factory_file()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 50 def create_factory_file file = File.join(options[:dir], "#{filename}.rb") create_file(file, single_file_factory_definition) end
factories_file()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 38 def factories_file options[:dir] + ".rb" end
factory_attributes()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 71 def factory_attributes attributes.map do |attribute| "#{attribute.name} #{attribute.default.inspect}" end.join("\n") end
factory_bot_options()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 89 def factory_bot_options generators.options[:factory_bot] || {} end
factory_definition()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 55 def factory_definition <<-RUBY factory :#{singular_table_name}#{explicit_class_option} do #{factory_attributes.gsub(/^/, " ")} end RUBY end
filename()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 77 def filename if factory_bot_options[:filename_proc].present? factory_bot_options[:filename_proc].call(table_name) else [table_name, filename_suffix].compact.join('_') end end
filename_suffix()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 85 def filename_suffix factory_bot_options[:suffix] || options[:suffix] end
generators()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 93 def generators config = FactoryBot::Railtie.config config.respond_to?(:app_generators) ? config.app_generators : config.generators end
insert_factory_into_existing_file()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 42 def insert_factory_into_existing_file insert_into_file( factories_file, factory_definition, after: "FactoryBot.define do\n" ) end
single_file_factory_definition()
click to toggle source
# File lib/generators/factory_bot/model/model_generator.rb, line 63 def single_file_factory_definition <<-RUBY FactoryBot.define do #{factory_definition.chomp} end RUBY end