module Pragma::Decorator::Association
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.
@example 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'] })
Public Class Methods
included(klass)
click to toggle source
# File lib/pragma/decorator/association.rb, line 22 def self.included(klass) klass.extend ClassMethods klass.include InstanceMethods end