class Yap::Filter
Public Class Methods
new()
click to toggle source
# File lib/yap/filter.rb, line 5 def initialize @failed = [] @columns = [] end
Public Instance Methods
not()
click to toggle source
# File lib/yap/filter.rb, line 22 def not extract_filters(:not) end
parse!(model, params)
click to toggle source
# File lib/yap/filter.rb, line 10 def parse!(model, params) params.each do |attribute, values| parse_arrtibute(model, attribute, values) end raise FilterError, "Cannot filter by: #{@failed.join(', ')}" unless @failed.empty? end
where()
click to toggle source
# File lib/yap/filter.rb, line 18 def where extract_filters(:where) end
Private Instance Methods
extract_filters(condition)
click to toggle source
# File lib/yap/filter.rb, line 28 def extract_filters(condition) @columns.inject({}) do |filter, column| values = column.send(condition) if values.empty? filter else filter.merge(column.name => values.size == 1 ? values.first : values) end end end
parse_arrtibute(model, attribute, values)
click to toggle source
# File lib/yap/filter.rb, line 40 def parse_arrtibute(model, attribute, values) column = model.map_column(attribute.to_s) if column.nil? @failed << attribute return end filter_column = FilterColumn.new(column) filter_column.parse_values(values) @columns << filter_column end