Class: SteelWheel::ScaffoldControllerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::ResourceHelpers
Defined in:
lib/generators/steel_wheel/scaffold_controller/scaffold_controller_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_filesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/steel_wheel/scaffold_controller/scaffold_controller_generator.rb', line 32

def copy_files
  if behavior == :revoke
    template 'index.rb', "app/handlers/#{controller_file_path}/index_handler.rb"
    template 'create.rb', "app/handlers/#{controller_file_path}/create_handler.rb"
    template 'update.rb', "app/handlers/#{controller_file_path}/update_handler.rb"
    template 'model_form.rb', "app/handlers/#{controller_file_path}/model_form.rb"
    template 'search_form.rb', "app/handlers/#{controller_file_path}/search_form.rb"
  elsif behavior == :invoke
    empty_directory Pathname.new('app/handlers').join(controller_file_path)
    template 'index.rb', "app/handlers/#{controller_file_path}/index_handler.rb"
    template 'create.rb', "app/handlers/#{controller_file_path}/create_handler.rb"
    template 'update.rb', "app/handlers/#{controller_file_path}/update_handler.rb"
    template 'model_form.rb', "app/handlers/#{controller_file_path}/model_form.rb"
    template 'search_form.rb', "app/handlers/#{controller_file_path}/search_form.rb"
  end
end

#copy_templateObject



24
25
26
27
28
29
30
# File 'lib/generators/steel_wheel/scaffold_controller/scaffold_controller_generator.rb', line 24

def copy_template
  if behavior == :revoke
    template 'form.tt', "lib/templates/erb/scaffold/_form.html.erb.tt"
  elsif behavior == :invoke
    create_file "lib/templates/erb/scaffold/_form.html.erb.tt", File.read(File.join(__dir__, 'templates', 'form.tt'))
  end
end

#create_controller_filesObject



19
20
21
22
# File 'lib/generators/steel_wheel/scaffold_controller/scaffold_controller_generator.rb', line 19

def create_controller_files
  template_file = options.api? ? "api_controller.rb" : "controller.rb"
  template template_file, File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
end