Sha256: 53ef5bd5b005250c6b99f2304d984b2155c2876354df99cd974633f323151ca1

Contents?: true

Size: 846 Bytes

Versions: 2

Compression:

Stored size: 846 Bytes

Contents

class FavouriteObject::FavouriteSerializer < ActiveModel::Serializer
  attributes :id, :target_id, :target_type, :is_favourited, :description, :third_party_flag, :data
  embed :ids, :include => true
  # has_one :target, polymorphic: true

  def include_target?
    (self.object.third_party_flag != true)
  end

  def description
  	if self.object.third_party_flag == true
  		self.object.params[:description]
  	else
  		self.object.message
  	end
  end

  def data
  	if self.object.third_party_flag == true
  		self.object.params
  	else
  		[]
  	end
  end

  def target_id
  	if self.object.third_party_flag == true
  		self.object.third_party_id
  	else
  		self.object.target_id
  	end
  end

  def target_type
  	if self.object.third_party_flag == true
  		self.object.third_party_type
  	else
  		self.object.target_type
  	end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
favourite_object-0.1.1 app/serializer/favourite_object/favourite_serializer.rb
favourite_object-0.1.0 app/serializer/favourite_object/favourite_serializer.rb