Class: Wallaby::Sorting::NextBuilder

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

Overview

Pass field_name to generate sort param for its next sort order (e.g. from empty to ‘asc`, from `asc` to `desc`, from `desc` to empty)

Constant Summary collapse

ASC =
'asc'.freeze
DESC =
'desc'.freeze

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)

    sorting hash



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

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

Instance Method Details

#next_params(field_name) ⇒ ActionController::Parameters

Update the ‘sort` parameter.

Examples:

for param ‘’name asc’‘, it will update the parameters

to `{sort: 'name desc'}`

Parameters:

  • field_name (String)

    field name

Returns:

  • (ActionController::Parameters)

    updated parameters that update the sort order for given field



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

def next_params(field_name)
  params = clean_params
  update params, :sort, complete_sorting_str_with(field_name)
  params
end