Sha256: 23cd8fcb718631766691bac2ddab353586b53b55d708ce670a79dc9f3510994d
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
module Datagrid module Filters module CompositeFilters def self.included(base) base.extend ClassMethods base.class_eval do end base.send :include, InstanceMethods end # self.included module ClassMethods 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}", :date, from_options) do |date, grid| grid.driver.greater_equal(self, field, date) end filter(to_options[:name] || :"to_#{field}", :date, to_options) do |date, grid| grid.driver.less_equal(self, field, date) end end 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}", :integer, from_options) do |value, grid| grid.driver.greater_equal(self, field, value) end filter(to_options[:name] || :"to_#{field}", :integer, to_options) do |value, grid| grid.driver.less_equal(self, field, value) end end def normalize_composite_filter_options(options, field) if options.is_a?(String) || options.is_a?(Symbol) options = {:name => options} end options end end # ClassMethods module InstanceMethods end # InstanceMethods end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
datagrid-0.6.0 | lib/datagrid/filters/composite_filters.rb |