Class: Wallaby::Sorting::NextBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/services/wallaby/sorting/next_builder.rb

Overview

Generate sort param for given field's next sort order (e.g. from empty to asc, from asc to desc, from desc to empty)

Direct Known Subclasses

SingleBuilder

Constant Summary collapse

ASC =
'asc'
DESC =
'desc'

Instance Method Summary collapse

Constructor Details

#initialize(params, hash = nil) ⇒ NextBuilder

Returns a new instance of NextBuilder.

Parameters:

  • params (ActionController::Parameters)
  • hash (Hash, nil) (defaults to: nil)

    a hash containing sorting info, e.g. { name: 'asc' }



13
14
15
16
# File 'lib/services/wallaby/sorting/next_builder.rb', line 13

def initialize(params, hash = nil)
  @params = params
  @hash = hash.try(:with_indifferent_access) || HashBuilder.build(params[:sort])
end

Instance Method Details

#next_params(field_name) ⇒ ActionController::Parameters

Update the sort parameter.

Examples:

for param {sort: 'name asc'}, it updates the parameters to:

{sort: 'name desc'}

Parameters:

  • field_name (String)

    field name

Returns:

  • (ActionController::Parameters)

    updated parameters with new sort order for given field



24
25
26
27
28
# File 'lib/services/wallaby/sorting/next_builder.rb', line 24

def next_params(field_name)
  params = Utils.clone @params
  params[:sort] = complete_sorting_str_with field_name
  params
end