Module: TableSortable::Concerns::Proc
- Extended by:
- ActiveSupport::Concern
- Included in:
- TableSortable::Column::Filter, TableSortable::Column::Sorter
- Defined in:
- lib/table_sortable/concerns/proc.rb
Instance Method Summary collapse
- #active_record_proc ⇒ Object
- #array_proc ⇒ Object
- #detect_method(proc, scope = nil) ⇒ Object
- #disabled? ⇒ Boolean
- #initialize(option_name, *options) ⇒ Object
- #method(record = nil) ⇒ Object
- #proc_wrapper(proc) ⇒ Object
- #run(records) ⇒ Object
- #used? ⇒ Boolean
Instance Method Details
#active_record_proc ⇒ Object
65 66 67 |
# File 'lib/table_sortable/concerns/proc.rb', line 65 def active_record_proc raise NotImplementedError end |
#array_proc ⇒ Object
61 62 63 |
# File 'lib/table_sortable/concerns/proc.rb', line 61 def array_proc raise NotImplementedError end |
#detect_method(proc, scope = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# 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? ⇒ Boolean
57 58 59 |
# File 'lib/table_sortable/concerns/proc.rb', line 57 def disabled? method.nil? end |
#initialize(option_name, *options) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/table_sortable/concerns/proc.rb', line 10 def initialize(option_name, *) = . unless [option_name] == false @type = option_name @column = [:column] the_proc = [option_name] || @column.name @method = ["#{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 |
#method(record = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
69 70 71 |
# File 'lib/table_sortable/concerns/proc.rb', line 69 def proc_wrapper(proc) raise NotImplementedError end |
#run(records) ⇒ Object
73 74 75 |
# File 'lib/table_sortable/concerns/proc.rb', line 73 def run(records) raise NotImplementedError end |
#used? ⇒ Boolean
77 78 79 |
# File 'lib/table_sortable/concerns/proc.rb', line 77 def used? raise NotImplementedError end |