Class: LightekVpm::Generators::ControllerGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- LightekVpm::Generators::ControllerGenerator
- Includes:
- GeneratorHelpers, Rails::Generators::ResourceHelpers
- Defined in:
- lib/generators/lightek_vpm/controller_generator.rb
Overview
Custom scaffolding generator
Instance Attribute Summary
Attributes included from GeneratorHelpers
Instance Method Summary collapse
- #add_abilities ⇒ Object
- #add_routes ⇒ Object
- #copy_controller_and_spec_files ⇒ Object
- #copy_view_files ⇒ Object
Instance Method Details
#add_abilities ⇒ Object
35 36 37 38 |
# File 'lib/generators/lightek_vpm/controller_generator.rb', line 35 def add_abilities ability_string = "\n can :manage, #{class_name}, user_id: user.id" inject_into_file "#{Rails.root}/app/models/ability.rb", ability_string, after: /def initialize[a-z()]+/i end |
#add_routes ⇒ Object
29 30 31 32 33 |
# File 'lib/generators/lightek_vpm/controller_generator.rb', line 29 def add_routes routes_string = "resources :#{singular_name}" routes_string += ', except: :show' unless show_action? route routes_string end |
#copy_controller_and_spec_files ⇒ Object
16 17 18 |
# File 'lib/generators/lightek_vpm/controller_generator.rb', line 16 def copy_controller_and_spec_files template 'controller.rb', File.join('app/controllers', "#{controller_file_name}_controller.rb") end |
#copy_view_files ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/generators/lightek_vpm/controller_generator.rb', line 20 def copy_view_files directory_path = File.join('app/views', controller_file_path) empty_directory directory_path view_files.each do |file_name| template "views/#{file_name}.html.erb", File.join(directory_path, "#{file_name}.html.erb") end end |