Class: ActiveRacksource::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/active_racksource/response.rb

Overview

A thin wrapper around Rack::Response

ActiveResource expects an HTTP Response object to be formatted in a certain way with the right methods, etc.

This object wraps a Rack::Response and implements an inferface that supports ActiveResource

Some methods called by ActiveResource:

code

string representation of status code, eg. ‘200’ or ‘404’

message

string message, eg. ‘OK’ or ‘Not Found’

body

string response body

Instance Method Summary collapse

Constructor Details

#initialize(rack_response) ⇒ Response

initialize a new ActiveRacksource::Response

Parameters

rack_response

a Rack::Response instance



23
24
25
# File 'lib/active_racksource/response.rb', line 23

def initialize rack_response
  @rack_response = rack_response
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object

by default, fall back to methods on the Rack::Response



44
45
46
# File 'lib/active_racksource/response.rb', line 44

def method_missing name, *args
  @rack_response.send name, *args
end

Instance Method Details

#codeObject



27
28
29
# File 'lib/active_racksource/response.rb', line 27

def code
  @rack_response.status.to_s
end

#messageObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/active_racksource/response.rb', line 31

def message
  if code.start_with?'2'
    'OK'
  elsif code.start_with?'4'
    'Not Found'
  elsif code.start_with?'3'
    'Redirect'
  else
    'Error'
  end
end