Class: JsonapiCompliable::Scoping::Paginate

Inherits:
Scoping::Base
  • Object
show all
Defined in:
lib/jsonapi_compliable/scoping/paginate.rb

Constant Summary collapse

MAX_PAGE_SIZE =
1_000

Instance Method Summary collapse

Instance Method Details

#apply ⇒ Object



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

def apply
  if size > MAX_PAGE_SIZE
    raise JsonapiCompliable::Errors::UnsupportedPageSize
      .new(size, MAX_PAGE_SIZE)
  else
    super
  end
end

#apply? ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/jsonapi_compliable/scoping/paginate.rb', line 14

def apply?
  if @opts[:default] == false
    not [page_param[:size], page_param[:number]].all?(&:nil?)
  else
    true
  end
end

#apply_custom_scope ⇒ Object



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

def apply_custom_scope
  custom_scope.call(@scope, number, size)
end

#apply_standard_scope ⇒ Object



26
27
28
# File 'lib/jsonapi_compliable/scoping/paginate.rb', line 26

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

#custom_scope ⇒ Object



22
23
24
# File 'lib/jsonapi_compliable/scoping/paginate.rb', line 22

def custom_scope
  resource.pagination
end