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
- #array_proc ⇒ Object
- #detect_method(proc) ⇒ Object
- #disabled? ⇒ Boolean
- #initialize(option_name, *options) ⇒ Object
- #sql_proc ⇒ Object
Instance Method Details
#array_proc ⇒ Object
38 39 40 |
# File 'lib/table_sortable/concerns/proc.rb', line 38 def array_proc raise NotImplementedError end |
#detect_method(proc) ⇒ Object
29 30 31 32 |
# File 'lib/table_sortable/concerns/proc.rb', line 29 def detect_method(proc) method = [].instance_exec('', &proc) rescue :failed method == :failed ? :sql : :array end |
#disabled? ⇒ Boolean
34 35 36 |
# File 'lib/table_sortable/concerns/proc.rb', line 34 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 |
# File 'lib/table_sortable/concerns/proc.rb', line 10 def initialize(option_name, *) = . unless [option_name] == false filter = [option_name] || [:column_name] @method = ["#{option_name.to_s}_method".to_sym] || :array if filter.respond_to? :call @proc = -> (records, col=nil) { instance_exec(records, &filter) } @method = detect_method(@proc) elsif !filter.nil? case @method when :array @proc = array_proc when :sql @proc = sql_proc end end end end |
#sql_proc ⇒ Object
42 43 44 |
# File 'lib/table_sortable/concerns/proc.rb', line 42 def sql_proc raise NotImplementedError end |