Class: Taro::Types::ObjectTypes::PageType
- Inherits:
-
ResponseType
- Object
- Struct
- BaseType
- Taro::Types::ObjectType
- ResponseType
- Taro::Types::ObjectTypes::PageType
- 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
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
Attributes inherited from BaseType
Attributes included from Shared::AdditionalProperties
Attributes included from Shared::Deprecation
Class Method Summary collapse
- .default_openapi_name ⇒ Object
- .derive_from(from_type) ⇒ Object
- .paginate(relation, after:, limit: 20, order_by: nil, order: nil) ⇒ Object
- .render(relation) ⇒ Object
Methods included from Shared::ItemType
Methods inherited from ResponseType
Methods included from Shared::Fields
Methods included from Shared::ObjectCoercion
#coerce_input, #coerce_response
Methods included from Shared::CustomFieldResolvers
Methods included from Shared::AdditionalProperties
#additional_properties?, #inherited
Methods included from Shared::DerivedTypes
#define_derived_type, #derived_types, map
Methods included from Shared::Description
Methods included from Shared::Equivalence
#equal_properties?, #equivalent?
Methods included from Shared::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
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_name ⇒ Object
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 |