class ActionDispatch::Routing::Mapper

Public Instance Methods

component(name, options = {}) click to toggle source
# 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) { || ... } click to toggle source

component_scope :api do

component :counter, actions: [:hoge]

end

will generate

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

# 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