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