Method: StandardAPI::RouteHelpers#standard_resource
- Defined in:
- lib/standard_api/route_helpers.rb
#standard_resource(*resource, &block) ⇒ Object
StandardAPI wrapper for ActionDispatch::Routing::Mapper::Resources#resource
Includes the following routes
GET /schema
GET /calculate
For example:
standard_resource :account
is equivilent to:
resource :account do
get :schema, on: :collection
get :calculate, on: :collection
end
77 78 79 80 81 82 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 110 |
# File 'lib/standard_api/route_helpers.rb', line 77 def standard_resource(*resource, &block) = resource..dup resource(*resource, ) do available_actions = if only = parent_resource.instance_variable_get(:@only) Array(only).map(&:to_sym) else if parent_resource.instance_variable_get(:@api_only) [:index, :create, :show, :update, :destroy] else [:index, :create, :new, :show, :update, :destroy, :edit] end + [ :schema, :calculate, :add_resource, :remove_resource ] end actions = if except = parent_resource.instance_variable_get(:@except) available_actions - Array(except).map(&:to_sym) else available_actions end get :schema, on: :collection if actions.include?(:schema) get :calculate, on: :collection if actions.include?(:calculate) if actions.include?(:add_resource) post ':relationship/:resource_id' => :add_resource, on: :member end if actions.include?(:remove_resource) delete ':relationship/:resource_id' => :remove_resource, on: :member end block.call if block end end |