Class: Gum::OrderBy

Inherits:
Filter show all
Defined in:
lib/gum/order.rb

Constant Summary collapse

ALLOWED_VALUES =
%w(asc desc).freeze

Instance Attribute Summary

Attributes inherited from Filter

#field, #options, #param

Instance Method Summary collapse

Methods inherited from Filter

#initialize, #render

Constructor Details

This class inherits a constructor from Gum::Filter

Instance Method Details

#__render__(value) ⇒ Object



5
6
7
# File 'lib/gum/order.rb', line 5

def __render__(value)
  { field => value }
end

#empty?(params) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/gum/order.rb', line 14

def empty?(params)
  ALLOWED_VALUES.exclude?(params[param].to_s) && options[:default].nil?
end

#value_from(params) ⇒ Object



9
10
11
12
# File 'lib/gum/order.rb', line 9

def value_from(params)
  value = super.to_s
  ALLOWED_VALUES.include?(value) ? value : options[:default]
end