Class: Poncho::JSONMethod
Instance Attribute Summary
Attributes inherited from Method
#env, #request, #response
Instance Method Summary
collapse
Methods inherited from Method
before, before_validation, call, #call, #client_error?, #content_type, error, #error, errors, #halt, #headers, helpers, #invoke, #not_found, #not_found?, #param, #param?, #param_before_type_cast, #params, #redirect, #redirect?, #server_error?, #status, #success?, to_proc
Methods included from Params
included
Methods included from Filters
included
#errors, included, #invalid?, #valid?
Instance Method Details
#body(value = nil) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/poncho/json_method.rb', line 25
def body(value = nil)
if value && !json_content_type?
content_type :json
value = value.to_json
end
super
end
|
#json(value) ⇒ Object
34
35
36
37
|
# File 'lib/poncho/json_method.rb', line 34
def json(value)
content_type :json
body(value.to_json)
end
|
#json? ⇒ Boolean
39
40
41
|
# File 'lib/poncho/json_method.rb', line 39
def json?
request.accept?(mime_type(:json))
end
|
#json_content_type? ⇒ Boolean
43
44
45
|
# File 'lib/poncho/json_method.rb', line 43
def json_content_type?
response['Content-Type'] == mime_type(:json)
end
|