Class: Faalis::Generators::ResourceGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/faalis/resource_generator.rb

Overview

Generate a resource on dashboard

Instance Method Summary collapse

Instance Method Details

#create_controllerObject


15
16
17
18
# File 'lib/generators/faalis/resource_generator.rb', line 15

def create_controller
  template('dashboard/controller.rb.erb',
           "app/controllers/dashboard/#{module_path}#{resources}_controller.rb")
end

#create_pundit_fileObject


11
12
13
# File 'lib/generators/faalis/resource_generator.rb', line 11

def create_pundit_file
  generate 'pundit:policy', resource_name
end

#inject_routesObject


20
21
22
23
24
# File 'lib/generators/faalis/resource_generator.rb', line 20

def inject_routes
  gsub_file('config/routes.rb',
            "in_dashboard do",
            "in_dashboard do\n    resources :#{resources}")
end

#warningObject


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/generators/faalis/resource_generator.rb', line 26

def warning
  unless module_name.blank?
    puts ""
    puts "[Warning] : Please fix your routes. Since you're using a resource inside"
    puts "            a namespace, you have to fixed your routes to point to your"
    puts "            new generate code. For example if you create a resource like"
    puts "            `School::Student`, then you should have your route like this:"
    puts ""
    puts "            in_dashboard do"
    puts "               namespace :school do"
    puts "                  resources students"
    puts "               end"
    puts "            end"
    puts ""
  end
end