Module: Roar::JSON::JSONAPI::Mixin

Defined in:
lib/roar/json/json_api.rb

Overview

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.

Examples:

Basic Usage

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

  type :songs
  property :id
end

See Also:

Class Method Summary collapse

Class Method Details

.included(base) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Hook called when module is included

Parameters:

  • base (Class, Module)

    the module or class including JSONAPI

Returns:

  • (undefined)

See Also:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# 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