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.



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lunetas/candy/response_handler.rb', line 34

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
23
24
25
26
27
28
29
# File 'lib/lunetas/candy/response_handler.rb', line 8

def handle_call
  case @req.request_method
  when 'GET'
    get
  when 'POST'
    post
  when 'PUT'
    put
  when 'DELETE'
    delete
  when 'HEAD'
    head
  when 'TRACE'
    trace
  when 'OPTIONS'
    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.



52
53
54
# File 'lib/lunetas/candy/response_handler.rb', line 52

def url_param(index)
  @lunetas_url_instance_params[index]
end