Class: Graphiti::Scoping::Paginate

Inherits:
Base show all
Defined in:
lib/graphiti/scoping/paginate.rb

Constant Summary collapse

DEFAULT_PAGE_SIZE =
20

Instance Attribute Summary

Attributes inherited from Base

#query_hash, #resource

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Graphiti::Scoping::Base

Instance Method Details

#applyObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/graphiti/scoping/paginate.rb', line 5

def apply
  if size > resource.max_page_size
    raise Graphiti::Errors::UnsupportedPageSize
      .new(size, resource.max_page_size)
  elsif requested? && @opts[:sideload_parent_length].to_i > 1
    raise Graphiti::Errors::UnsupportedPagination
  else
    super
  end
end

#apply?Boolean

We want to apply this logic unless we’ve explicitly received the default: false option. In that case, only apply if pagination was explicitly specified in the request.

Returns:

  • (Boolean)

    should we apply this logic?



21
22
23
24
25
26
27
# File 'lib/graphiti/scoping/paginate.rb', line 21

def apply?
  if @opts[:default_paginate] == false
    requested?
  else
    true
  end
end

#apply_custom_scopeObject

Apply the custom pagination proc



40
41
42
# File 'lib/graphiti/scoping/paginate.rb', line 40

def apply_custom_scope
  resource.instance_exec(@scope, number, size, resource.context, &custom_scope)
end

#apply_standard_scopeObject

Apply default pagination proc via the Resource adapter



35
36
37
# File 'lib/graphiti/scoping/paginate.rb', line 35

def apply_standard_scope
  resource.adapter.paginate(@scope, number, size)
end

#custom_scopeProc, Nil

Returns the custom pagination proc.

Returns:

  • (Proc, Nil)

    the custom pagination proc



30
31
32
# File 'lib/graphiti/scoping/paginate.rb', line 30

def custom_scope
  resource.pagination
end