Class: Taro::Types::ObjectTypes::PageType

Inherits:
ResponseType show all
Extended by:
Shared::ItemType
Defined in:
lib/taro/types/object_types/page_type.rb

Overview

Abstract base class for Page types (paginated ActiveRecord data). Unlike other types, this one should not be manually inherited from, but is used indirectly via ‘page_of: SomeType`.

The gem rails_cursor_pagination must be installed to use this.

Direct Known Subclasses

PageWithTotalCountType

Constant Summary

Constants included from Shared::OpenAPIFormat

Shared::OpenAPIFormat::OPENAPI_INTEGER_FORMATS, Shared::OpenAPIFormat::OPENAPI_NUMBER_FORMATS, Shared::OpenAPIFormat::OPENAPI_STRING_FORMATS

Constants included from Shared::OpenAPIType

Shared::OpenAPIType::OPENAPI_TYPES

Instance Attribute Summary

Attributes included from Shared::ItemType

#item_type

Attributes inherited from BaseType

#object

Attributes included from Shared::AdditionalProperties

#additional_properties

Attributes included from Shared::Deprecation

#deprecated

Class Method Summary collapse

Methods included from Shared::ItemType

raise_mixed_types

Methods inherited from ResponseType

#coerce_input

Methods included from Shared::Fields

#field, #fields

Methods included from Shared::ObjectCoercion

#coerce_input, #coerce_response

Methods included from Shared::CustomFieldResolvers

included, #resolve?

Methods included from Shared::AdditionalProperties

#additional_properties?, #inherited

Methods included from Shared::DerivedTypes

#define_derived_type, #derived_types, map

Methods included from Shared::Description

#desc, #desc=

Methods included from Shared::Equivalence

#equal_properties?, #equivalent?

Methods included from Shared::Name

#define_name

Methods included from Shared::OpenAPIFormat

#inherited, #openapi_format, #openapi_format=

Methods included from Shared::OpenAPIName

#default_openapi_name, #openapi_name, #openapi_name=

Methods included from Shared::OpenAPIType

#inherited, #openapi_type, #openapi_type=

Methods included from Shared::Rendering

#last_render, #last_render=, #render, #used_in_response

Methods included from Shared::TypeClass

included

Methods included from Shared::Errors

#coerce_error_message, #input_error, #response_error

Methods included from Shared::Caching

#cached_coerce_response, included

Class Method Details

.default_openapi_nameObject



28
29
30
# File 'lib/taro/types/object_types/page_type.rb', line 28

def self.default_openapi_name
  "#{item_type.openapi_name}_Page"
end

.derive_from(from_type) ⇒ Object



10
11
12
13
14
# File 'lib/taro/types/object_types/page_type.rb', line 10

def self.derive_from(from_type)
  super
  field(:page, array_of: from_type.name)
  field(:page_info, type: 'Taro::Types::ObjectTypes::PageInfoType')
end

.paginate(relation, after:, limit: 20, order_by: nil, order: nil) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/taro/types/object_types/page_type.rb', line 20

def self.paginate(relation, after:, limit: 20, order_by: nil, order: nil)
  result = RailsCursorPagination::Paginator.new(
    relation, limit:, order_by:, order:, after:
  ).fetch
  result[:page].map! { |el| el.fetch(:data) }
  result
end

.render(relation) ⇒ Object



16
17
18
# File 'lib/taro/types/object_types/page_type.rb', line 16

def self.render(relation, **)
  super(paginate(relation, **))
end