Sha256: 57d0849bbec87e776409d5dcff52be50d3960b57d10d85588fa02a1e6164f904

Contents?: true

Size: 587 Bytes

Versions: 6

Compression:

Stored size: 587 Bytes

Contents

class BMC::Sorter
  include BMC::SortingHelper

  attr_reader :collection, :sort_param, :column, :direction

  def initialize(collection, sort_param = nil)
    @collection         = collection
    @sort_param         = sort_param
    @column, @direction = sortable_column_order(sort_param.to_s)
  end

  def sort
    raise NotImplementedError
  end

  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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bmc-1.3.0 app/sorters/bmc/sorter.rb
bmc-1.2.1 app/sorters/bmc/sorter.rb
bmc-1.2.0 app/sorters/bmc/sorter.rb
bmc-1.1.0 app/sorters/bmc/sorter.rb
bmc-1.0.1 app/sorters/bmc/sorter.rb
bmc-1.0.0 app/sorters/bmc/sorter.rb