Class: Toller::Sort
- Inherits:
-
Object
- Object
- Toller::Sort
- Defined in:
- lib/toller/sort.rb
Overview
Sort
Instance Attribute Summary collapse
-
#parameter ⇒ Object
readonly
Returns the value of attribute parameter.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #apply!(collection, direction = :asc) ⇒ Object
- #default ⇒ Object
-
#initialize(parameter, type, options) ⇒ Sort
constructor
A new instance of Sort.
Constructor Details
#initialize(parameter, type, options) ⇒ Sort
Returns a new instance of Sort.
10 11 12 13 14 15 16 17 18 |
# File 'lib/toller/sort.rb', line 10 def initialize(parameter, type, ) @parameter = parameter @type = type @properties = .reverse_merge( field: parameter, default: false, scope_name: nil ) end |
Instance Attribute Details
#parameter ⇒ Object (readonly)
Returns the value of attribute parameter.
8 9 10 |
# File 'lib/toller/sort.rb', line 8 def parameter @parameter end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/toller/sort.rb', line 8 def properties @properties end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/toller/sort.rb', line 8 def type @type end |
Instance Method Details
#apply!(collection, direction = :asc) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/toller/sort.rb', line 20 def apply!(collection, direction = :asc) if type == :scope Sorts::ScopeHandler.new.call(collection, direction, properties) else Sorts::OrderHandler.new.call(collection, direction, properties) end end |
#default ⇒ Object
28 29 30 |
# File 'lib/toller/sort.rb', line 28 def default properties[:default] end |