Skip to content

Instantly share code, notes, and snippets.

@workmad3
Forked from bogn/v1_group_serializer.rb
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workmad3/6f7e7c9fac51aeeb800a to your computer and use it in GitHub Desktop.
Save workmad3/6f7e7c9fac51aeeb800a to your computer and use it in GitHub Desktop.
module Export
module V1
class GroupSerializer < ActiveModel::Serializers
attributes :items
def items_serializer
ItemsSerializer
end
def items
docs = object.items.order_by(:position.asc)
items_serializer.new(docs, special_options).serializable_hash
end
end
end
end
module Export
module V1
class ItemsSerializer < ActiveModel::Serializer
# ...
end
end
end
module Export
module V2
class GroupSerializer < ::Export::V1::GroupSerializer
def items_serializer
ItemsSerializer
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment