Module: Lunetas::Candy::ResponseHandler::InstanceMethods

Defined in:
lib/lunetas/candy/response_handler.rb

Instance Method Summary collapse

Instance Method Details

#biteArray

Bites the Candy (a.k.a process this resource).

Returns:

  • (Array)

    a standard rack response.



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lunetas/candy/response_handler.rb', line 27

def bite
  raise @_error if @_error
  before
  response(handle_call)
rescue Exception => e
  code, error = 500, e
  if Lunetas::Error::BaseError === e
    code = e.code
  elsif development?
    error = "Error: #{e.message}\nBacktrace: #{e.backtrace.join("\n")}"
  end
  response(error, code)
end

#handle_callArray

Handles the rack call. Delegates it to the method that matches the request method.

Returns:

  • (Array)

    a Rack::Request response.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lunetas/candy/response_handler.rb', line 8

def handle_call
  case @req.request_method
  when 'GET'     then get
  when 'POST'    then post
  when 'PUT'     then put
  when 'DELETE'  then delete
  when 'HEAD'    then head
  when 'TRACE'   then trace
  when 'OPTIONS' then options
  else
    response = other_verb(@req.request_method)
    raise Lunetas::Error::APIError unless response
    response
  end
end

#url_param(index) ⇒ String

Returns the url parameter from the regular expresion. If a captured block is given, then they will be added in order of appearance.

Parameters:

  • index (Fixnum)

    the index of the captured block.

Returns:

  • (String)

    the captured block.



45
46
47
# File 'lib/lunetas/candy/response_handler.rb', line 45

def url_param(index)
  @lunetas_url_instance_params[index]
end