2018-09-28 22:03:04 -04:00
|
|
|
require "rails/generators/named_base"
|
2011-07-11 23:11:06 -04:00
|
|
|
|
2016-12-02 10:25:09 -05:00
|
|
|
module FactoryBot
|
2011-07-11 23:11:06 -04:00
|
|
|
module Generators
|
|
|
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
|
|
|
def self.source_root
|
2018-09-28 22:34:23 -04:00
|
|
|
path = File.join(
|
|
|
|
File.dirname(__FILE__),
|
|
|
|
"factory_bot",
|
|
|
|
generator_name,
|
|
|
|
"templates",
|
|
|
|
)
|
|
|
|
|
|
|
|
File.expand_path(path)
|
2011-07-11 23:11:06 -04:00
|
|
|
end
|
2012-02-26 13:58:48 -05:00
|
|
|
|
2020-04-03 21:50:47 -04:00
|
|
|
def factory_name
|
|
|
|
class_name.gsub("::", "").underscore
|
|
|
|
end
|
|
|
|
|
2012-02-26 13:58:48 -05:00
|
|
|
def explicit_class_option
|
2020-04-03 21:50:47 -04:00
|
|
|
return if class_name.underscore == factory_name
|
2018-09-28 22:34:23 -04:00
|
|
|
|
|
|
|
", class: '#{class_name}'"
|
2012-02-26 13:58:48 -05:00
|
|
|
end
|
2011-07-11 23:11:06 -04:00
|
|
|
end
|
|
|
|
end
|
2012-02-26 13:58:48 -05:00
|
|
|
end
|