Class: Wallaby::ModelPaginator

Inherits:
Object
  • Object
show all
Extended by:
Baseable::ClassMethods
Defined in:
lib/paginators/wallaby/model_paginator.rb

Overview

This is the base paginator class to provider pagination for given collection.

For best practice, please create an application paginator class (see example) to better control the functions shared between different model paginators.

Examples:

Create an application class for Admin Interface usage

class Admin::ApplicationPaginator < Wallaby::ModelPaginator
  base_class!
end

Instance Attribute Summary collapse

Attributes included from Baseable::ClassMethods

#base_class

Instance Method Summary collapse

Methods included from Baseable::ClassMethods

base_class!, base_class?, namespace, namespace=

Constructor Details

#initialize(model_class, collection, params) ⇒ ModelPaginator

Returns a new instance of ModelPaginator.

Parameters:

  • model_class (Class)
  • collection (#to_a)

    a collection of the resources

  • params (ActionController::Parameters)

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
# File 'lib/paginators/wallaby/model_paginator.rb', line 28

def initialize(model_class, collection, params)
  @model_class = self.class.model_class || model_class
  raise ArgumentError, 'Please provide a `model_class`.' unless @model_class

  @collection = collection
  @params = params
  @provider = Map.pagination_provider_map(@model_class).new(@collection, @params)
end

Instance Attribute Details

#model_classClass (readonly)

Returns:

  • (Class)


18
19
20
# File 'lib/paginators/wallaby/model_paginator.rb', line 18

def model_class
  @model_class
end

#providerModelPaginationProvider (readonly)

Returns the instance that does the job.

Returns:

Since:

  • wallaby-5.2.0



23
24
25
# File 'lib/paginators/wallaby/model_paginator.rb', line 23

def provider
  @provider
end

Instance Method Details

#first_page?Boolean

Check and see if it’s the first page

Returns:

  • (Boolean)


# File 'lib/paginators/wallaby/model_paginator.rb', line 40

#first_page_numberInteger

Page number of first page

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 67

#fromInteger

Find out the offset ‘from`

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 52

#last_page?Boolean

Check and see if it’s the last page

Returns:

  • (Boolean)


# File 'lib/paginators/wallaby/model_paginator.rb', line 46

#last_page_numberInteger

Page number of last page

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 70

#next_page?Boolean

Check and see if it’s the next page

Returns:

  • (Boolean)


# File 'lib/paginators/wallaby/model_paginator.rb', line 49

#next_page_numberInteger

Page number of next page

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 76

#number_of_pagesInteger

Total number of pages

Returns:

  • (Integer)


82
# File 'lib/paginators/wallaby/model_paginator.rb', line 82

delegate(*ModelPaginationProvider.instance_methods(false), to: :provider)

#page_numberInteger

Find out the current page number

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 64

#page_sizeInteger

Find out the current page size

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 61

#paginatable?Boolean

If a collection has pagination feature

Returns:

  • (Boolean)


# File 'lib/paginators/wallaby/model_paginator.rb', line 37

#prev_page?Boolean

Check and see if it’s the previous page

Returns:

  • (Boolean)


# File 'lib/paginators/wallaby/model_paginator.rb', line 43

#prev_page_numberInteger

Page number of previous page

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 73

#toInteger

Find out the offset ‘to`

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 55

#totalInteger

Find out the total count of current query

Returns:

  • (Integer)


# File 'lib/paginators/wallaby/model_paginator.rb', line 58