Skip to content

Instantly share code, notes, and snippets.

@bogn
Created April 29, 2014 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bogn/cfbd3e4528cf3dcd7f94 to your computer and use it in GitHub Desktop.
Save bogn/cfbd3e4528cf3dcd7f94 to your computer and use it in GitHub Desktop.
versioned API through inheritance
module Export
module V1
class GroupSerializer < ActiveModel::Serializers
attributes :items
def items
docs = object.items.order_by(:position.asc)
ItemsSerializer.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
end
end
end
@bogn
Copy link
Author

bogn commented Apr 29, 2014

Export::V2::GroupSerializer#items works with Export::V1::ItemsSerializer in line 9 while I want it to work with the one from it's own namespace (Export::V2::ItemsSerializer) even though it uses the items method from V1. Is that even possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment