Module: Pragma::Decorator::Association

Defined in:
lib/pragma/decorator/association.rb,
lib/pragma/decorator/association/bond.rb,
lib/pragma/decorator/association/errors.rb,
lib/pragma/decorator/association/adapter.rb,
lib/pragma/decorator/association/reflection.rb,
lib/pragma/decorator/association/adapter/base.rb,
lib/pragma/decorator/association/adapter/poro.rb,
lib/pragma/decorator/association/adapter/active_record.rb

Overview

Associations provide a way to define related records on your decorators.

Once you define an association, it can be expanded by API clients through the expand query parameter to load the full record.

Examples:

Defining and expanding an association

class ArticleDecorator < Pragma::Decorator::Base
  belongs_to :author, decorator: API::V1::User::Decorator
end

# This will return a hash whose `author` key is the ID of the article's author.
ArticleDecorator.new(article).to_hash

# This will return a hash whose `author` key is a hash representing the decorated
# article's author.
ArticleDecorator.new(article).to_hash(user_options: { expand: ['author'] })

Defined Under Namespace

Modules: Adapter, ClassMethods, InstanceMethods Classes: AssociationNotFound, Bond, ExpansionError, InconsistentTypeError, Reflection, UnexpandedAssociationParent

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



22
23
24
25
# File 'lib/pragma/decorator/association.rb', line 22

def self.included(klass)
  klass.extend ClassMethods
  klass.include InstanceMethods
end