Class: Agilibox::Sorter

Inherits:
Object
  • Object
show all
Includes:
SortingHelper
Defined in:
app/sorters/agilibox/sorter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#collectionObject (readonly)

Returns the value of attribute collection.



4
5
6
# File 'app/sorters/agilibox/sorter.rb', line 4

def collection
  @collection
end

#columnObject (readonly)

Returns the value of attribute column.



4
5
6
# File 'app/sorters/agilibox/sorter.rb', line 4

def column
  @column
end

#directionObject (readonly)

Returns the value of attribute direction.



4
5
6
# File 'app/sorters/agilibox/sorter.rb', line 4

def direction
  @direction
end

#sort_paramObject (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

#callObject



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

#sortObject

Raises:

  • (NotImplementedError)


12
13
14
# File 'app/sorters/agilibox/sorter.rb', line 12

def sort
  raise NotImplementedError
end