Class: JsonapiCompliable::Scope::Paginate

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

Constant Summary collapse

MAX_PAGE_SIZE =
1_000

Instance Attribute Summary

Attributes inherited from Base

#controller, #dsl, #params, #scope

Instance Method Summary collapse

Methods inherited from Base

#apply_standard_or_override, #apply_standard_scope?, #initialize

Constructor Details

This class inherits a constructor from JsonapiCompliable::Scope::Base

Instance Method Details

#apply ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/jsonapi_compliable/scope/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_custom_scope ⇒ Object



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

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

#apply_standard_scope ⇒ Object



18
19
20
# File 'lib/jsonapi_compliable/scope/paginate.rb', line 18

def apply_standard_scope
  @scope.page(number).per(size)
end

#custom_scope ⇒ Object



14
15
16
# File 'lib/jsonapi_compliable/scope/paginate.rb', line 14

def custom_scope
  dsl.pagination
end