Sha256: e7c76649687c1d460eb5a2e80e73bf5701718be4bf9bbf9fef5453c1fdc123c1

Contents?: true

Size: 754 Bytes

Versions: 33

Compression:

Stored size: 754 Bytes

Contents

module TableSortable
  class Column
    class Sorter
      include TableSortable::Concerns::Proc

      attr_accessor :sort_order

      def initialize(*args)
        super :sort, *args
      end

      def array_proc
        -> (sort_order, col=nil) { sort{ |a,b| col.value(sort_order == :asc ? a : b) <=> col.value(sort_order == :asc ? b : a) } }
      end

      def active_record_proc
        -> (sort_order, col=nil) { order(col.name.to_s.underscore => sort_order) }
      end

      def proc_wrapper(proc)
        -> (sort_order, col=nil) { instance_exec(sort_order , &proc) }
      end

      def run(records)
        records.instance_exec(sort_order, column, &proc)
      end

      def used?
        !sort_order.nil?
      end

    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
table_sortable-1.0.0.pre.alpha.21 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.20 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.19 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.18 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.17 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.16 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.15 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.14 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.13 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.12 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.11 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.10 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.9 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.8 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.7 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.6 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.5 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.4 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.3 lib/table_sortable/column/sorter.rb
table_sortable-1.0.0.pre.alpha.2 lib/table_sortable/column/sorter.rb