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

- (Object) controller_module (private)



56
57
58
59
# File 'lib/generators/faalis/resource_generator.rb', line 56

def controller_module
  path = module_path + 'dashboard/'
  path.classify
end

- (Object) create_controller



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

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

- (Object) create_pundit_file



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

def create_pundit_file
  generate 'pundit:policy', resource
end

- (Object) inject_routes



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

- (Object) module_name (private)



44
45
46
# File 'lib/generators/faalis/resource_generator.rb', line 44

def module_name
  resource_name.underscore.split('/')[0..-2].join('/')
end

- (Object) module_path (private)



48
49
50
51
52
53
54
# File 'lib/generators/faalis/resource_generator.rb', line 48

def module_path
  if !module_name.blank?
    module_name + '/'
  else
    ''
  end
end

- (Object) resource (private)



61
62
63
# File 'lib/generators/faalis/resource_generator.rb', line 61

def resource
  resource_name.underscore.split('/')[-1].singularize
end

- (Object) resources (private)



65
66
67
# File 'lib/generators/faalis/resource_generator.rb', line 65

def resources
  resource.pluralize
end

- (Object) warning



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 "               scope :school do"
    puts "                  resources students"
    puts "               end"
    puts "            end"
    puts ""
  end
end