Class: RoadForest::Resource::RDF::ReadOnly
- Inherits:
-
Webmachine::Resource
- Object
- Webmachine::Resource
- RoadForest::Resource::RDF::ReadOnly
show all
- Defined in:
- lib/roadforest/resource/read-only.rb
Overview
Used for a resource that presents a read-only representation
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#content_engine ⇒ Object
Returns the value of attribute content_engine.
18
19
20
|
# File 'lib/roadforest/resource/read-only.rb', line 18
def content_engine
@content_engine
end
|
#interface ⇒ Object
Returns the value of attribute interface.
18
19
20
|
# File 'lib/roadforest/resource/read-only.rb', line 18
def interface
@interface
end
|
#trace ⇒ Object
Returns the value of attribute trace.
18
19
20
|
# File 'lib/roadforest/resource/read-only.rb', line 18
def trace
@trace
end
|
Class Method Details
.register(method_name) ⇒ Object
12
13
14
|
# File 'lib/roadforest/resource/read-only.rb', line 12
def self.register(method_name)
RoadForest::Resource.registry.add(method_name, self)
end
|
Instance Method Details
#content_types_provided ⇒ Object
85
86
87
88
89
|
# File 'lib/roadforest/resource/read-only.rb', line 85
def content_types_provided
content_engine.renderers.type_map
rescue
super
end
|
#error_data(status) ⇒ Object
110
111
112
|
# File 'lib/roadforest/resource/read-only.rb', line 110
def error_data(status)
@interface.error_data(status)
end
|
#expires ⇒ Object
134
135
136
|
# File 'lib/roadforest/resource/read-only.rb', line 134
def expires
@interface.expires
end
|
#finish_request ⇒ Object
XXX Add cache-control headers here
104
105
106
107
108
|
# File 'lib/roadforest/resource/read-only.rb', line 104
def finish_request
if (400..499).include? response.code
set_error_body(response.code)
end
end
|
#generate_etag ⇒ Object
126
127
128
|
# File 'lib/roadforest/resource/read-only.rb', line 126
def generate_etag
@interface.etag
end
|
#interface_supports(action) ⇒ Object
def known_methods
super + ["PATCH"]
end
55
56
57
|
# File 'lib/roadforest/resource/read-only.rb', line 55
def interface_supports(action)
@interface.respond_to?(action)
end
|
#is_authorized?(header) ⇒ Boolean
95
96
97
98
99
100
101
|
# File 'lib/roadforest/resource/read-only.rb', line 95
def is_authorized?()
@authorization = @interface.authorization(request)
if(@authorization == :public || @authorization == :granted)
return true
end
@interface.authentication_challenge
end
|
#last_modified ⇒ Object
130
131
132
|
# File 'lib/roadforest/resource/read-only.rb', line 130
def last_modified
@interface.last_modified
end
|
#method(name) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/roadforest/resource/read-only.rb', line 75
def method(name)
if interface.nil?
super
else
content_engine.fetch(name).method(:call)
end
rescue KeyError
super
end
|
#params ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/roadforest/resource/read-only.rb', line 22
def params
Application::Parameters.new do |params|
params.path_info = @request.path_info
params.query_params = @request.query
params.path_tokens = @request.path_tokens
end
end
|
34
35
36
|
# File 'lib/roadforest/resource/read-only.rb', line 34
def
request.["Accept"] || "*/*"
end
|
#request_uri ⇒ Object
30
31
32
|
# File 'lib/roadforest/resource/read-only.rb', line 30
def request_uri
request.uri.to_s.sub(/[?]\Z/, '')
end
|
#required_grants(method) ⇒ Object
91
92
93
|
# File 'lib/roadforest/resource/read-only.rb', line 91
def required_grants(method)
@interface.required_grants(method)
end
|
#resource_exists? ⇒ Boolean
122
123
124
|
# File 'lib/roadforest/resource/read-only.rb', line 122
def resource_exists?
@interface.exists?
end
|
#response_body=(body) ⇒ Object
42
43
44
|
# File 'lib/roadforest/resource/read-only.rb', line 42
def response_body=(body)
response.body = body
end
|
#response_content_type=(type) ⇒ Object
38
39
40
|
# File 'lib/roadforest/resource/read-only.rb', line 38
def response_content_type=(type)
response.["Content-Type"] = type
end
|
#retrieve_interface ⇒ Object
Also known as:
retreive_interface
46
47
48
|
# File 'lib/roadforest/resource/read-only.rb', line 46
def retrieve_interface
absolutize(@interface.canonical_host, @interface.retrieve)
end
|
#send(*args) ⇒ Object
Overridden rather than metaprogram content type methods
65
66
67
68
69
70
71
72
73
|
# File 'lib/roadforest/resource/read-only.rb', line 65
def send(*args)
if args.length == 1 and not interface.nil?
content_engine.fetch(args.first).call(self)
else
super
end
rescue KeyError
super
end
|
#set_error_body(status) ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/roadforest/resource/read-only.rb', line 114
def set_error_body(status)
data= error_data(status)
return "" if data.nil?
renderer = content_engine.choose_renderer(request.["Accept"])
response.["Content-Type"] = renderer.type.
response.body = renderer.local_to_network(request_uri, data)
end
|
#trace? ⇒ Boolean
60
61
62
|
# File 'lib/roadforest/resource/read-only.rb', line 60
def trace?
!!@trace
end
|