2012-05-09 17:32:58 +00:00
|
|
|
module Rails
|
|
|
|
module Generators
|
2017-04-05 18:43:27 +00:00
|
|
|
class DecoratorGenerator < NamedBase
|
2017-07-20 13:51:30 +00:00
|
|
|
source_root File.expand_path("templates", __dir__)
|
2013-02-05 11:24:40 +00:00
|
|
|
check_class_collision suffix: "Decorator"
|
2012-05-09 17:32:58 +00:00
|
|
|
|
2013-02-05 11:24:40 +00:00
|
|
|
class_option :parent, type: :string, desc: "The parent class for the generated decorator"
|
2012-05-09 17:32:58 +00:00
|
|
|
|
|
|
|
def create_decorator_file
|
|
|
|
template 'decorator.rb', File.join('app/decorators', class_path, "#{file_name}_decorator.rb")
|
|
|
|
end
|
|
|
|
|
|
|
|
hook_for :test_framework
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def parent_class_name
|
2013-02-05 11:24:40 +00:00
|
|
|
options.fetch("parent") do
|
|
|
|
begin
|
|
|
|
require 'application_decorator'
|
|
|
|
ApplicationDecorator
|
|
|
|
rescue LoadError
|
|
|
|
"Draper::Decorator"
|
|
|
|
end
|
2012-05-09 17:32:58 +00:00
|
|
|
end
|
|
|
|
end
|
2012-12-03 22:51:58 +00:00
|
|
|
end
|
2012-05-09 17:32:58 +00:00
|
|
|
end
|
|
|
|
end
|