Class: ActionDispatch::Routing::Mapper

Inherits:
Object
  • Object
show all
Defined in:
lib/server_component/engine/routes.rb

Instance Method Summary collapse

Instance Method Details

#component(name, options = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/server_component/engine/routes.rb', line 25

def component(name, options = {})
  actions = [options.fetch(:actions, [])].flatten(1)
  actions.each do |action|
    post "/#{name}/#{action}", controller: "#{name}_component", action: action
  end
  @current_component_router.add_component(name)
end

#component_scope(*args) ⇒ Object

component_scope :api do

component :counter, actions: [:hoge]

end

will generate

/api => Description Endpoint /api/counter/hoge => Component Endpoints



14
15
16
17
18
19
20
21
22
23
# File 'lib/server_component/engine/routes.rb', line 14

def component_scope(*args)
  path = args.first.to_s
  get "/#{path}", controller: 'server_component/component_routers', action: 'show', name: path
  namespace(*args) do
    @current_component_router = ServerComponent::ComponentRouter.new(@scope[:module])
    yield
  end
  ServerComponent.mappings[path] = @current_component_router
  @current_component_router = nil
end