Class: TableSortable::Column::Filter
- Inherits:
-
Object
- Object
- TableSortable::Column::Filter
- Includes:
- TableSortable::Concerns::Proc
- Defined in:
- lib/table_sortable/column/filter.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#query ⇒ Object
Returns the value of attribute query.
Instance Method Summary collapse
- #active_record_proc ⇒ Object
- #array_proc ⇒ Object
-
#initialize(*args) ⇒ Filter
constructor
A new instance of Filter.
- #proc_wrapper(proc) ⇒ Object
- #run(records) ⇒ Object
- #used? ⇒ Boolean
Methods included from TableSortable::Concerns::Proc
#detect_method, #disabled?, #method
Constructor Details
#initialize(*args) ⇒ Filter
Returns a new instance of Filter.
8 9 10 11 12 13 |
# File 'lib/table_sortable/column/filter.rb', line 8 def initialize(*args) = args. @default_value = [:filter_initial_value] @collection = [:filter_collection] super :filter, end |
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
6 7 8 |
# File 'lib/table_sortable/column/filter.rb', line 6 def collection @collection end |
#default_value ⇒ Object
Returns the value of attribute default_value.
6 7 8 |
# File 'lib/table_sortable/column/filter.rb', line 6 def default_value @default_value end |
#query ⇒ Object
Returns the value of attribute query.
6 7 8 |
# File 'lib/table_sortable/column/filter.rb', line 6 def query @query end |
Instance Method Details
#active_record_proc ⇒ Object
19 20 21 |
# File 'lib/table_sortable/column/filter.rb', line 19 def active_record_proc -> (value, col=nil) { where("LOWER(#{col.name.to_s.underscore}) LIKE (?)", "%#{value.to_s.downcase}%") } end |
#array_proc ⇒ Object
15 16 17 |
# File 'lib/table_sortable/column/filter.rb', line 15 def array_proc -> (value, col=nil) { select{|record| col.value(record).to_s.downcase.include? value.downcase} } end |
#proc_wrapper(proc) ⇒ Object
23 24 25 |
# File 'lib/table_sortable/column/filter.rb', line 23 def proc_wrapper(proc) -> (value, col=nil) { instance_exec(value, &proc) } end |
#run(records) ⇒ Object
27 28 29 |
# File 'lib/table_sortable/column/filter.rb', line 27 def run(records) records.instance_exec(query, column, &proc) end |
#used? ⇒ Boolean
31 32 33 |
# File 'lib/table_sortable/column/filter.rb', line 31 def used? !query.nil? end |