Class: Agilibox::Sorter
- Inherits:
-
Object
- Object
- Agilibox::Sorter
- Includes:
- SortingHelper
- Defined in:
- app/sorters/agilibox/sorter.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#direction ⇒ Object
readonly
Returns the value of attribute direction.
-
#sort_param ⇒ Object
readonly
Returns the value of attribute sort_param.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(collection, sort_param = nil) ⇒ Sorter
constructor
A new instance of Sorter.
- #sort ⇒ Object
Methods included from SortingHelper
#sortable_column, #sortable_column_order
Constructor Details
#initialize(collection, sort_param = nil) ⇒ Sorter
Returns a new instance of Sorter.
6 7 8 9 10 |
# File 'app/sorters/agilibox/sorter.rb', line 6 def initialize(collection, sort_param = nil) @collection = collection @sort_param = sort_param @column, @direction = sortable_column_order(sort_param.to_s) end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
4 5 6 |
# File 'app/sorters/agilibox/sorter.rb', line 4 def collection @collection end |
#column ⇒ Object (readonly)
Returns the value of attribute column.
4 5 6 |
# File 'app/sorters/agilibox/sorter.rb', line 4 def column @column end |
#direction ⇒ Object (readonly)
Returns the value of attribute direction.
4 5 6 |
# File 'app/sorters/agilibox/sorter.rb', line 4 def direction @direction end |
#sort_param ⇒ Object (readonly)
Returns the value of attribute sort_param.
4 5 6 |
# File 'app/sorters/agilibox/sorter.rb', line 4 def sort_param @sort_param end |
Class Method Details
.call(*args) ⇒ Object
23 24 25 |
# File 'app/sorters/agilibox/sorter.rb', line 23 def self.call(*args) new(*args).call end |
Instance Method Details
#call ⇒ Object
16 17 18 19 20 21 |
# File 'app/sorters/agilibox/sorter.rb', line 16 def call # Don't replace by `collection.reorder(sort)` # #sort can change #collection and must be called before #collection order = sort collection.reorder(order) end |
#sort ⇒ Object
12 13 14 |
# File 'app/sorters/agilibox/sorter.rb', line 12 def sort raise NotImplementedError end |