Method: Roar::JSON::JSONAPI.resource

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

.resource(type, options = {}) ⇒ Object

Include to define a JSON API Resource and make API methods available to your Roar::Decorator.

Examples:

Basic Usage

class SongsRepresenter < Roar::Decorator
  include Roar::JSON::JSONAPI.resource :songs
end

Custom ID key

class SongsRepresenter < Roar::Decorator
  include Roar::JSON::JSONAPI.resource :songs, id_key: :song_id
end

Parameters:

  • type (Symbol, String)

    type name of this resource.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :id_key (Symbol)

    custom ID key for this resource.

See Also:



70
71
72
# File 'lib/roar/json/json_api.rb', line 70

def self.resource(type, options = {})
  Resource.new(type, options)
end