Sha256: 665a1d63d141ed05c19f3eedf360e6e9253b5dae9a97e9c062946f3d7088fcef
Contents?: true
Size: 1.66 KB
Versions: 6
Compression:
Stored size: 1.66 KB
Contents
module MyApp class Post attr_accessor :id attr_accessor :title attr_accessor :body attr_accessor :author attr_accessor :long_comments end class LongComment attr_accessor :id attr_accessor :body attr_accessor :user attr_accessor :post end class User attr_accessor :id attr_accessor :name end class PostSerializer include JSONAPI::Serializer attribute :title attribute :long_content do object.body end has_one :author has_many :long_comments end class LongCommentSerializer include JSONAPI::Serializer attribute :body has_one :user # Circular-reference back to post. has_one :post end class UserSerializer include JSONAPI::Serializer attribute :name end # More customized, one-off serializers to test particular behaviors: class SimplestPostSerializer include JSONAPI::Serializer attribute :title attribute :long_content do object.body end def type :posts end end class PostSerializerWithMetadata include JSONAPI::Serializer attribute :title attribute :long_content do object.body end def type 'posts' # Intentionally test string type. end def meta { 'copyright' => 'Copyright 2015 Example Corp.', 'authors' => ['Aliens'], } end end class PostSerializerWithContextHandling < SimplestPostSerializer include JSONAPI::Serializer attribute :body, if: :show_body?, unless: :hide_body? def show_body? context.fetch(:show_body, true) end def hide_body? context.fetch(:hide_body, false) end end end
Version data entries
6 entries across 6 versions & 1 rubygems