Class: ManyfoldApi::V0::GroupListSerializer
- Inherits:
-
ApplicationSerializer
- Object
- ApplicationSerializer
- ManyfoldApi::V0::GroupListSerializer
- Defined in:
- app/serializers/manyfold_api/v0/group_list_serializer.rb
Instance Method Summary collapse
- #groups_path(options = {}) ⇒ Object
-
#initialize(creator, groups) ⇒ GroupListSerializer
constructor
A new instance of GroupListSerializer.
- #serialize ⇒ Object
Methods inherited from ApplicationSerializer
#collection_ref, #context, #creator_ref, #file_ref, #group_ref, #license, #model_ref, #ref, schema, schema_ref, schema_ref_name
Constructor Details
#initialize(creator, groups) ⇒ GroupListSerializer
Returns a new instance of GroupListSerializer.
3 4 5 6 |
# File 'app/serializers/manyfold_api/v0/group_list_serializer.rb', line 3 def initialize(creator, groups) @creator = creator super(groups) end |
Instance Method Details
#groups_path(options = {}) ⇒ Object
8 9 10 |
# File 'app/serializers/manyfold_api/v0/group_list_serializer.rb', line 8 def groups_path( = {}) Rails.application.routes.url_helpers.creator_groups_path(@creator, ) end |
#serialize ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/serializers/manyfold_api/v0/group_list_serializer.rb', line 12 def serialize { "@context": context, "@id": groups_path, "@type": "hydra:Collection", totalItems: @object.total_count, member: @object.map { |group| { "@id": Rails.application.routes.url_helpers.creator_group_path(@creator, group), name: group.name } }, view: { "@id": groups_path(page: @object.current_page), "@type": "hydra:PartialCollectionView", first: groups_path(page: 1), previous: (groups_path(page: @object.prev_page) if @object.prev_page), next: (groups_path(page: @object.next_page) if @object.next_page), last: groups_path(page: @object.total_pages) }.compact } end |