Class: Toast::CanonicalRequest

Inherits:
Object
  • Object
show all
Includes:
Errors, RequestHelpers
Defined in:
lib/toast/canonical_request.rb

Instance Method Summary collapse

Methods included from RequestHelpers

#allowed_methods, #attr_selected?, #base_uri, #call_allow, #call_handler, #get_config, #is_active_record?, #represent, #represent_one, #response, #split_link_header

Constructor Details

#initialize(id, base_config, auth, request) ⇒ CanonicalRequest

Returns a new instance of CanonicalRequest.



7
8
9
10
11
12
13
14
15
16
# File 'lib/toast/canonical_request.rb', line 7

def initialize id, base_config, auth, request
  @id          = id
  @base_config = base_config
  @selected_attributes = request.query_parameters[:toast_select].try(:split,/ *, */)
  @uri_params  = request.query_parameters
  @base_uri    = base_uri(request)
  @verb        = request.request_method.downcase
  @auth        = auth
  @request     = request
end

Instance Method Details

#respondObject



18
19
20
21
22
23
24
25
26
# File 'lib/toast/canonical_request.rb', line 18

def respond
  if @verb.in? %w(get patch put delete)
    self.send(@verb)
  else
    response :method_not_allowed,
             headers: {'Allow' => allowed_methods(@base_config)},
             msg: "method #{@verb.upcase} not supported for collection URIs"
  end
end