Module: Ballast::Concerns::JSONApi::ResponseHandling
- Defined in:
- lib/ballast/concerns/json_api/response_handling.rb
Overview
A concern to handle JSON API responses.
Instance Attribute Summary collapse
-
#included ⇒ Object
Returns the value of attribute included.
Instance Method Summary collapse
-
#response_data(default = nil) ⇒ HashWithIndifferentAccess
Returns the data for the current response.
-
#response_include(object, template = nil) ⇒ HashWithIndifferentAccess
Adds a object to the set of included objects.
-
#response_included(default = nil) ⇒ HashWithIndifferentAccess
Returns the additionally included objects for the current response.
-
#response_links(default = nil) ⇒ HashWithIndifferentAccess
Returns the links for the current response.
-
#response_meta(default = nil) ⇒ HashWithIndifferentAccess
Returns the metadata for the current response.
-
#response_template_for(object) ⇒ String
Returns the template for a object.
-
#response_timestamp(timestamp) ⇒ String
Formats a timestamp in ISO 8601 format.
Instance Attribute Details
#included ⇒ Object
Returns the value of attribute included.
6 7 8 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 6 def included @included end |
Instance Method Details
#response_data(default = nil) ⇒ HashWithIndifferentAccess
Returns the data for the current response.
29 30 31 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 29 def response_data(default = nil) @data || default || HashWithIndifferentAccess.new end |
#response_include(object, template = nil) ⇒ HashWithIndifferentAccess
Adds a object to the set of included objects.
54 55 56 57 58 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 54 def response_include(object, template = nil) controller.included ||= HashWithIndifferentAccess.new controller.included[sprintf("%s:%s", response_template_for(object), object.to_param)] = [object, template] controller.included end |
#response_included(default = nil) ⇒ HashWithIndifferentAccess
Returns the additionally included objects for the current response.
45 46 47 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 45 def response_included(default = nil) controller.included || default || HashWithIndifferentAccess.new end |
#response_links(default = nil) ⇒ HashWithIndifferentAccess
Returns the links for the current response.
37 38 39 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 37 def response_links(default = nil) @links || default || HashWithIndifferentAccess.new end |
#response_meta(default = nil) ⇒ HashWithIndifferentAccess
Returns the metadata for the current response.
21 22 23 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 21 def (default = nil) @meta || default || HashWithIndifferentAccess.new end |
#response_template_for(object) ⇒ String
Returns the template for a object. It can overriden by setting the @object_template
variable.
11 12 13 14 15 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 11 def response_template_for(object) return @object_template if @object_template object = object.first if object.respond_to?(:first) object.class.name.underscore.gsub("/", "_") end |
#response_timestamp(timestamp) ⇒ String
Formats a timestamp in ISO 8601 format.
64 65 66 |
# File 'lib/ballast/concerns/json_api/response_handling.rb', line 64 def () .safe_send(:strftime, "%FT%T.%L%z") end |