Class: TableSortable::Column::Sorter
Instance Attribute Summary collapse
Instance Method Summary
collapse
#detect_method, #disabled?, #method
Constructor Details
#initialize(*args) ⇒ Sorter
Returns a new instance of Sorter.
8
9
10
|
# File 'lib/table_sortable/column/sorter.rb', line 8
def initialize(*args)
super :sort, *args
end
|
Instance Attribute Details
#sort_order ⇒ Object
Returns the value of attribute sort_order.
6
7
8
|
# File 'lib/table_sortable/column/sorter.rb', line 6
def sort_order
@sort_order
end
|
Instance Method Details
#active_record_proc ⇒ Object
16
17
18
|
# File 'lib/table_sortable/column/sorter.rb', line 16
def active_record_proc
-> (sort_order, col=nil) { order(col.name.to_s.underscore => sort_order) }
end
|
#array_proc ⇒ Object
12
13
14
|
# File 'lib/table_sortable/column/sorter.rb', line 12
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
|
#proc_wrapper(proc) ⇒ Object
20
21
22
|
# File 'lib/table_sortable/column/sorter.rb', line 20
def proc_wrapper(proc)
-> (sort_order, col=nil) { instance_exec(sort_order , &proc) }
end
|
#run(records) ⇒ Object
24
25
26
|
# File 'lib/table_sortable/column/sorter.rb', line 24
def run(records)
records.instance_exec(sort_order, column, &proc)
end
|
#used? ⇒ Boolean
28
29
30
|
# File 'lib/table_sortable/column/sorter.rb', line 28
def used?
!sort_order.nil?
end
|