Class: LightekVpm::Generators::ControllerGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
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

#attributes, #options

Instance Method Summary collapse

Instance Method Details

#add_abilitiesObject



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_routesObject



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_filesObject



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_filesObject



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