Class: Restfulness::Resource
Constant Summary
Restfulness::Resources::Events::EXCEPTION_EVENTS, Restfulness::Resources::Events::SUCCESS_EVENTS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#authenticate_with_http_basic
#error!
Constructor Details
#initialize(request, response) ⇒ Resource
Returns a new instance of Resource.
9
10
11
12
|
# File 'lib/restfulness/resource.rb', line 9
def initialize(request, response)
@request = request
@response = response
end
|
Instance Attribute Details
#request ⇒ Object
Returns the value of attribute request.
7
8
9
|
# File 'lib/restfulness/resource.rb', line 7
def request
@request
end
|
#response ⇒ Object
Returns the value of attribute response.
7
8
9
|
# File 'lib/restfulness/resource.rb', line 7
def response
@response
end
|
Class Method Details
.supported_methods ⇒ Object
109
110
111
|
# File 'lib/restfulness/resource.rb', line 109
def supported_methods
@_actions ||= (instance_methods & [:get, :put, :post, :delete, :head, :patch, :options])
end
|
Instance Method Details
#allowed? ⇒ Boolean
42
43
44
|
# File 'lib/restfulness/resource.rb', line 42
def allowed?
true
end
|
#authorized? ⇒ Boolean
38
39
40
|
# File 'lib/restfulness/resource.rb', line 38
def authorized?
true
end
|
#call ⇒ Object
22
23
24
25
26
|
# File 'lib/restfulness/resource.rb', line 22
def call
send(request.action)
end
|
#check_callbacks ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/restfulness/resource.rb', line 54
def check_callbacks
set_locale
method_not_allowed! unless method_allowed?
unauthorized! unless authorized?
forbidden! unless allowed?
if [:head, :get, :patch, :delete].include?(request.action)
resource_not_found! unless exists?
if [:get, :head].include?(request.action)
check_etag if etag
check_if_modified if last_modified
end
end
end
|
#etag ⇒ Object
50
51
52
|
# File 'lib/restfulness/resource.rb', line 50
def etag
nil
end
|
#exists? ⇒ Boolean
34
35
36
|
# File 'lib/restfulness/resource.rb', line 34
def exists?
true
end
|
#last_modified ⇒ Object
46
47
48
|
# File 'lib/restfulness/resource.rb', line 46
def last_modified
nil
end
|
#method_allowed? ⇒ Boolean
30
31
32
|
# File 'lib/restfulness/resource.rb', line 30
def method_allowed?
self.class.supported_methods.include?(request.action)
end
|
#options ⇒ Object
Options is the only HTTP method support by default
15
16
17
18
19
20
|
# File 'lib/restfulness/resource.rb', line 15
def options
response.['Allow'] = self.class.supported_methods.map{ |m|
m.to_s.upcase
}.join(', ')
nil
end
|