Class: ActiveModel::Serializer::Attribute

Inherits:
Field
  • Object
show all
Defined in:
lib/active_model/serializer/attribute.rb

Overview

Holds all the meta-data about an attribute as it was specified in the ActiveModel::Serializer class.

Examples:

class PostSerializer < ActiveModel::Serializer
  attribute :content
  attribute :name, key: :title
  attribute :email, key: :author_email, if: :user_logged_in?
  attribute :preview do
    truncate(object.content)
  end

  def user_logged_in?
    current_user.logged_in?
  end
end

Instance Attribute Summary

Attributes inherited from Field

#block, #name, #options

Method Summary

Methods inherited from Field

#excluded?, #initialize, #value

Constructor Details

This class inherits a constructor from ActiveModel::Serializer::Field