class Sleek::Filter
Attributes
operator[R]
property_name[R]
value[R]
Public Class Methods
new(property_name, operator, value)
click to toggle source
Internal: Initialize a filter.
property_name
- the String name of target property. operator - the Symbol operator name. value - the value used by operator to compare with the
value of target property.
# File lib/sleek/filter.rb, line 11 def initialize(property_name, operator, value) @property_name = "d.#{property_name}" @operator = operator.to_sym @value = value unless [:eq, :ne, :lt, :lte, :gt, :gte, :in].include? @operator raise ArgumentError, "unsupported operator - #{operator}" end end
Public Instance Methods
==(other)
click to toggle source
Internal: Compare the filter with another. Filters are equal when property name, operator name, and value are equal.
# File lib/sleek/filter.rb, line 30 def ==(other) other.is_a?(Filter) && property_name == other.property_name && operator == other.operator && value == other.value end
apply(criteria)
click to toggle source
Internal: Apply the filter to a criteria.
criteria - the Mongoid::Criteria object.
# File lib/sleek/filter.rb, line 24 def apply(criteria) criteria.send(operator, property_name => value) end