module TableSortable::Concerns::Proc
Public Class Methods
new(option_name, *options)
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 10 def initialize(option_name, *options) options = options.extract_options! unless options[option_name] == false @type = option_name @column = options[:column] the_proc = options[option_name] || @column.name @method = options["#{option_name.to_s}_method".to_sym] || :autodetect if the_proc.respond_to? :call @proc = proc_wrapper(the_proc) @method = detect_method(@proc) elsif !the_proc.nil? case @method when :array @proc = array_proc when :active_record @proc = active_record_proc end end end end
Public Instance Methods
active_record_proc()
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 65 def active_record_proc raise NotImplementedError end
array_proc()
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 61 def array_proc raise NotImplementedError end
detect_method(proc, scope = nil)
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 31 def detect_method(proc, scope = nil) begin [].instance_exec('', &proc) method = :array rescue NoMethodError method = :active_record end method end
disabled?()
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 57 def disabled? method.nil? end
method(record = nil)
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 41 def method(record = nil) return @method if record.nil? if @method == :autodetect if record.class.columns.map{|col| col.name.to_sym}.include? @column.name method = :active_record @proc = active_record_proc else method = :array @proc = array_proc end else method = @method end method end
proc_wrapper(proc)
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 69 def proc_wrapper(proc) raise NotImplementedError end
run(records)
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 73 def run(records) raise NotImplementedError end
used?()
click to toggle source
# File lib/table_sortable/concerns/proc.rb, line 77 def used? raise NotImplementedError end