module Aepic::Concerns::Controller::Overrides

Protected Instance Methods

_render_option_json(resource, options) click to toggle source

@see jsonapi.org/format/ Singular resources are represented as JSON objects. However, they are still wrapped inside an array: {“posts”: [{ … }]} This simplifies processing, as you can know that a resource key will always be a list.

Calls superclass method
# File lib/aepic/concerns/controller.rb, line 87
def _render_option_json(resource, options)
  options[:meta] ||= {}

  etags = combine_etags(resource)
  key = ActiveSupport::Cache.expand_cache_key(etags)
  etag = %("#{Digest::MD5.hexdigest(key)}")
  options[:meta][:etag] = etag

  resource = Array.wrap(resource) unless resource.respond_to?(:length)
  if resource.respond_to?(:total_count)
    options[:meta][:total] = resource.total_count
  end

  json = ActiveModel::Serializer.build_json(self, resource, options)

  if json
    super(json, options)
  else
    super
  end
end
build_resource() click to toggle source

@return [Draper::Decorator]

Calls superclass method
# File lib/aepic/concerns/controller.rb, line 72
def build_resource
  get_resource_ivar || set_resource_ivar(resource_decorator.decorate(super))
end
collection() click to toggle source

@return [Draper::CollectionDecorator]

Calls superclass method
# File lib/aepic/concerns/controller.rb, line 77
def collection
  get_collection_ivar || set_collection_ivar(resource_decorator.decorate_collection(super))
end
resource() click to toggle source

@return [Draper::Decorator]

Calls superclass method
# File lib/aepic/concerns/controller.rb, line 67
def resource
  get_resource_ivar || set_resource_ivar(resource_decorator.decorate(super))
end
resource_decorator() click to toggle source

@return [Draper::Decorator]

# File lib/aepic/concerns/controller.rb, line 62
def resource_decorator
  self.class.resource_decorator
end
resource_serializer() click to toggle source

@return [ActiveModel::Serializer]

# File lib/aepic/concerns/controller.rb, line 57
def resource_serializer
  self.class.resource_serializer
end