Module: WithPagination
- Included in:
- ActivityPub::ReleasesOutboxSerializer, ClusterSerializer, ContainerRepositoriesSerializer, EnvironmentSerializer, FeatureFlagSerializer, GroupChildSerializer, GroupSerializer, Import::GithubFailureSerializer, Integrations::HarborSerializers::ArtifactSerializer, Integrations::HarborSerializers::RepositorySerializer, Integrations::HarborSerializers::TagSerializer, Integrations::ProjectSerializer, PipelineSerializer, StageSerializer
- Defined in:
- app/serializers/concerns/with_pagination.rb
Instance Attribute Summary collapse
-
#paginator ⇒ Object
Returns the value of attribute paginator.
Instance Method Summary collapse
- #paginated? ⇒ Boolean
-
#represent(resource, opts = {}) ⇒ Object
super is ‘BaseSerializer#represent` here.
- #with_pagination(request, response) ⇒ Object
Instance Attribute Details
#paginator ⇒ Object
Returns the value of attribute paginator.
4 5 6 |
# File 'app/serializers/concerns/with_pagination.rb', line 4 def paginator @paginator end |
Instance Method Details
#paginated? ⇒ Boolean
10 11 12 |
# File 'app/serializers/concerns/with_pagination.rb', line 10 def paginated? paginator.present? end |
#represent(resource, opts = {}) ⇒ Object
super is ‘BaseSerializer#represent` here.
we shouldn’t try to paginate single resources
17 18 19 20 21 22 23 |
# File 'app/serializers/concerns/with_pagination.rb', line 17 def represent(resource, opts = {}) if paginated? && resource.respond_to?(:page) super(paginator.paginate(resource), opts) else super(resource, opts) end end |
#with_pagination(request, response) ⇒ Object
6 7 8 |
# File 'app/serializers/concerns/with_pagination.rb', line 6 def with_pagination(request, response) tap { self.paginator = Gitlab::Serializer::Pagination.new(request, response) } end |