Class: Rails::Generators::LeoscaGenerator

Inherits:
ScaffoldGenerator
  • Object
show all
Includes:
Leonardo::Nested
Defined in:
lib/generators/rails/leosca/leosca_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_resource_routeObject

Override



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/generators/rails/leosca/leosca_generator.rb', line 17

def add_resource_route
  return if options[:actions].present?

  route_config = ""
  iparent = 0

  if nested?
    plural_parent_resources.each do |m|
      iparent += 2
      indent = eval "/^\s{#{16 - iparent}}/"
      route_config << <<-FILE.gsub(indent, '')
        resources :#{m} do
            get :with_#{file_name.pluralize}
            post :select,           :on => :collection
            post :edit_multiple,    :on => :collection
            put  :update_multiple,  :on => :collection
            put  :create_multiple,  :on => :collection
      FILE
    end
  end
  route_config << base_namespaces.map{|m| "namespace :#{m} do " }.join(" ") if leospaced?
  route_config << regular_class_path.map{|m| "namespace :#{m} do " }.join(" ")
  indent = eval "/^\s{#{8 - iparent}}/"
  route_config << <<-FILE.gsub(indent, '')

    resources :#{file_name.pluralize} do
      post :select,           :on => :collection
      post :edit_multiple,    :on => :collection
      put  :update_multiple,  :on => :collection
      put  :create_multiple,  :on => :collection
    end
  FILE
  route_config << "  end" * (regular_class_path.size + plural_parent_resources.size + base_namespaces.size)
  route route_config
end