Module: Wallaby::Paginatable

Included in:
ResourcesConcern, ResourcesHelper
Defined in:
lib/concerns/wallaby/paginatable.rb

Overview

Paginator related attributes

Instance Method Summary collapse

Instance Method Details

#current_paginatorClass

Model paginator for current modal class.

Returns:

  • (Class)

    model paginator class

See Also:



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/concerns/wallaby/paginatable.rb', line 9

def current_paginator
  @current_paginator ||=
    PaginatorFinder.new(
      script_name: script_name,
      model_class: current_model_class,
      current_controller_class: wallaby_controller
    ).execute.try do |klass|
      Logger.debug %(Current paginator: #{klass}), sourcing: false
      klass.new current_model_class, collection, pagination_params_for(params)
    end
end

#paginate(query, options = { paginate: true }) ⇒ #each

To paginate the collection but only when either ‘page` or `per` param is given, or HTML response is requested

Parameters:

  • query (#each)
  • options (Hash) (defaults to: { paginate: true })

Options Hash (options):

  • :paginate (Boolean)

    whether collection should be paginated

Returns:

  • (#each)

See Also:



28
29
30
31
32
# File 'lib/concerns/wallaby/paginatable.rb', line 28

def paginate(query, options = { paginate: true })
  return query unless options[:paginate]

  current_servicer.paginate(query, pagination_params_for(params))
end

#pagination_params_for(params) ⇒ Hash, ActionController::Parameters

Parameters:

  • params (Hash, ActionController::Parameters)

Returns:

  • (Hash, ActionController::Parameters)


36
37
38
39
# File 'lib/concerns/wallaby/paginatable.rb', line 36

def pagination_params_for(params)
  params[:per] ||= wallaby_controller.page_size
  params
end