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)
-
- (Object) included
Returns the value of attribute included.
Instance Method Summary (collapse)
-
- (HashWithIndifferentAccess) response_data(default = nil)
Returns the data for the current response.
-
- (HashWithIndifferentAccess) response_include(object, template = nil)
Adds a object to the set of included objects.
-
- (HashWithIndifferentAccess) response_included(default = nil)
Returns the additionally included objects for the current response.
-
- (HashWithIndifferentAccess) response_links(default = nil)
Returns the links for the current response.
-
- (HashWithIndifferentAccess) response_meta(default = nil)
Returns the metadata for the current response.
-
- (String) response_template_for(object)
Returns the template for a object.
-
- (String) response_timestamp(timestamp)
Formats a timestamp in ISO 8601 format.
Instance Attribute Details
- (Object) included
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
- (HashWithIndifferentAccess) response_data(default = nil)
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 |
- (HashWithIndifferentAccess) response_include(object, template = nil)
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 |
- (HashWithIndifferentAccess) response_included(default = nil)
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 |
- (HashWithIndifferentAccess) response_links(default = nil)
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 |
- (HashWithIndifferentAccess) response_meta(default = nil)
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 |
- (String) response_template_for(object)
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 |
- (String) response_timestamp(timestamp)
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 |