Module: Datagrid::Filters::CompositeFilters::ClassMethods

Defined in:
lib/datagrid/filters/composite_filters.rb

Overview

self.included

Instance Method Summary collapse

Instance Method Details

#date_range_filters(field, from_options = {}, to_options = {}) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
# File 'lib/datagrid/filters/composite_filters.rb', line 15

def date_range_filters(field, from_options = {}, to_options = {})
  from_options = normalize_composite_filter_options(from_options, field)
  to_options = normalize_composite_filter_options(to_options, field)

  filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :date, from_options) do |date, scope, grid|
    grid.driver.greater_equal(scope, field, date)
  end
  filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :date, to_options) do |date, scope, grid|
    grid.driver.less_equal(scope, field, date)
  end
end

#integer_range_filters(field, from_options = {}, to_options = {}) ⇒ Object


27
28
29
30
31
32
33
34
35
36
# File 'lib/datagrid/filters/composite_filters.rb', line 27

def integer_range_filters(field, from_options = {}, to_options = {})
  from_options = normalize_composite_filter_options(from_options, field)
  to_options = normalize_composite_filter_options(to_options, field)
  filter(from_options[:name] || :"from_#{field.to_s.tr('.', '_')}", :integer, from_options) do |value, scope, grid|
    grid.driver.greater_equal(scope, field, value)
  end
  filter(to_options[:name] || :"to_#{field.to_s.tr('.', '_')}", :integer, to_options) do |value, scope, grid|
    grid.driver.less_equal(scope, field, value)
  end
end

#normalize_composite_filter_options(options, field) ⇒ Object


38
39
40
41
42
43
# File 'lib/datagrid/filters/composite_filters.rb', line 38

def normalize_composite_filter_options(options, field)
  if options.is_a?(String) || options.is_a?(Symbol)
    options = {:name => options}
  end
  options
end