module Roar::JSON::JSONAPI::Mixin

Include to make API methods available to your `Roar::Decorator`.

Unlike {Resource}, you must define a `type` (by calling {Declarative#type}) and `id` property separately.

@example Basic Usage

class SongsRepresenter < Roar::Decorator
  include Roar::JSON::JSONAPI::Mixin

  type :songs
  property :id
end

@see Resource @api semi-public

Public Class Methods

included(base) click to toggle source

Hook called when module is included

@param [Class,Module] base

the module or class including JSONAPI

@return [undefined]

@api private @see www.ruby-doc.org/core/Module.html#method-i-included

# File lib/roar/json/json_api.rb, line 99
def self.included(base)
  base.class_eval do
    feature Roar::JSON
    feature Roar::Hypermedia
    feature JSONAPI::Defaults, JSONAPI::Meta
    extend JSONAPI::Declarative
    extend JSONAPI::ForCollection
    include JSONAPI::Document
    include JSONAPI::SingleResource
    self.representation_wrap = :data

    nested :relationships do
    end

    nested :included do
      def to_hash(*)
        super.flat_map { |_, resource| resource }
      end
    end
  end
end

Public Instance Methods

to_hash(*) click to toggle source
# File lib/roar/json/json_api.rb, line 114
def to_hash(*)
  super.flat_map { |_, resource| resource }
end