Class: BMC::Sorter

Inherits:
Object
  • Object
show all
Includes:
SortingHelper
Defined in:
app/sorters/bmc/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, options = {}) ⇒ Sorter

Returns a new instance of Sorter.



10
11
12
13
14
15
# File 'app/sorters/bmc/sorter.rb', line 10

def initialize(collection, sort_param, options = {})
  @collection = collection
  @sort_param = sort_param
  @options = options
  @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/bmc/sorter.rb', line 4

def collection
  @collection
end

#columnObject (readonly)

Returns the value of attribute column.



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

def column
  @column
end

#directionObject (readonly)

Returns the value of attribute direction.



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

def direction
  @direction
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

#sort_paramObject (readonly)

Returns the value of attribute sort_param.



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

def sort_param
  @sort_param
end

Class Method Details

.callObject



6
7
8
# File 'app/sorters/bmc/sorter.rb', line 6

def self.call(...)
  new(...).call
end

Instance Method Details

#callObject



21
22
23
24
25
26
# File 'app/sorters/bmc/sorter.rb', line 21

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)


17
18
19
# File 'app/sorters/bmc/sorter.rb', line 17

def sort
  raise NotImplementedError
end