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

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

  controller = options.fetch(:controller, "#{ component_name }_component")

  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)

        common_component_routes(options)
      end
    end
  end
end

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



40
41
42
43
44
45
46
47
48
49
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
# File 'lib/rails/routing_mapper.rb', line 40

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, 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')

  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

            common_component_routes(options)
          end
        end
      end
    end
  end
end

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rails/routing_mapper.rb', line 83

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')

  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

          common_component_routes(options)
        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