Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/rails/routing_mapper.rb

Instance Method Summary collapse

Instance Method Details

#component(component_name, options = {}, &block) ⇒ Object



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
# File 'lib/rails/routing_mapper.rb', line 17

def component(component_name, options = {}, &block)
  as, controller, component, endpoint = component_informations_from(
    component_name, options
  )

  actions = options.fetch(:actions, [:show])

  imports_controller = options.fetch(:imports_controller, '/para/admin/imports')
  exports_controller = options.fetch(:exports_controller, '/para/admin/exports')


  constraints Para::Routing::ComponentNameConstraint.new(component) do
    namespace :admin do
      defaults(component: component) do
        resource endpoint, controller: controller, as: as
      end

      scope(endpoint, as: component_name, defaults: { component: component }) do
        instance_eval(&block) if block
        add_extensions_for(:component)

        scope ':importer' do
          resources :imports, controller: imports_controller
        end

        scope ':exporter' do
          resources :exports, controller: exports_controller
        end
      end
    end
  end
end

#crud_component(component_name = nil, options = {}, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rails/routing_mapper.rb', line 50

def crud_component(component_name = nil, options = {}, &block)
  if !component_name || Hash === component_name
    options = component_name || {}
    component_name = :crud
    options[:scope] ||= ':model'
  end

  as, controller, component, endpoint = component_informations_from(
    component_name, options
  )

  # By default, use absolute paths to para default controllers, avoiding
  # namespacing issues in plugins and other module namespaced scenarios
  #
  controller = options.fetch(:controller, '/para/admin/crud_resources')
  imports_controller = options.fetch(:imports_controller, '/para/admin/imports')
  exports_controller = options.fetch(:exports_controller, '/para/admin/exports')

  constraints Para::Routing::ComponentNameConstraint.new(component) do
    constraints Para::Routing::ComponentControllerConstraint.new(controller) do
      namespace :admin do
        scope(endpoint, as: as, defaults: { component: component }) do
          scope options[:scope] do
            resources :resources, controller: controller do
              collection do
                patch :order
                patch :tree
              end

              member do
                post :clone
              end

              instance_eval(&block) if block
              add_extensions_for(:crud_component)
            end

            scope ':importer' do
              resources :imports, controller: imports_controller
            end

            scope ':exporter' do
              resources :exports, controller: exports_controller
            end
          end
        end
      end
    end
  end
end

#form_component(component_name = nil, options = {}, &block) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/rails/routing_mapper.rb', line 101

def form_component(component_name = nil, options = {}, &block)
  if !component_name || Hash === component_name
    options = component_name || {}
    component_name = :form
    options[:scope] ||= ':model'
  end

  as, _, component, endpoint = component_informations_from(
    component_name, options
  )

  controller = options.fetch(:controller, '/para/admin/form_resources')
  imports_controller = options.fetch(:imports_controller, '/para/admin/imports')
  exports_controller = options.fetch(:exports_controller, '/para/admin/exports')

  constraints Para::Routing::ComponentNameConstraint.new(component) do
    constraints Para::Routing::ComponentControllerConstraint.new(controller) do
      namespace :admin do
        scope(endpoint, as: as, defaults: { component: component }) do
          resource :resource, controller: controller, only: [:show, :create, :update] do
            add_extensions_for(:form_component)
          end

          scope ':importer' do
            resources :imports, controller: imports_controller
          end

          scope ':exporter' do
            resources :exports, controller: exports_controller
          end
        end
      end
    end
  end
end

#para_at(mount_location, &block) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rails/routing_mapper.rb', line 4

def para_at(mount_location, &block)
  Para::Routes.new(self).draw(mount_location, &block)

  Para::Config.plugins.each do |plugin|
    draw_plugin_routes(plugin)
  end
end

#para_plugin(plugin_name) ⇒ Object



12
13
14
15
# File 'lib/rails/routing_mapper.rb', line 12

def para_plugin(plugin_name)
  routes = ['', plugin_name.to_s.camelize, 'Routes'].join('::').constantize
  routes.new(self).draw
end