class Ransack::Predicate

Attributes

arel_predicate[R]
compound[R]
formatter[R]
name[R]
type[R]
validator[R]
wants_array[R]

Public Class Methods

detect_and_strip_from_string!(str) click to toggle source
# File lib/ransack/predicate.rb, line 20
def detect_and_strip_from_string!(str)
  if p = detect_from_string(str)
    str.sub! /_#{p}$/, Constants::EMPTY
    p
  end
end
detect_from_string(str) click to toggle source
# File lib/ransack/predicate.rb, line 27
def detect_from_string(str)
  names_by_decreasing_length.detect { |p| str.end_with?("_#{p}") }
end
named(name) click to toggle source
# File lib/ransack/predicate.rb, line 16
def named(name)
  Ransack.predicates[name.to_s]
end
names() click to toggle source
# File lib/ransack/predicate.rb, line 8
def names
  Ransack.predicates.keys
end
names_by_decreasing_length() click to toggle source
# File lib/ransack/predicate.rb, line 12
def names_by_decreasing_length
  names.sort { |a,b| b.length <=> a.length }
end
new(opts = {}) click to toggle source
# File lib/ransack/predicate.rb, line 43
def initialize(opts = {})
  @name = opts[:name]
  @arel_predicate = opts[:arel_predicate]
  @type = opts[:type]
  @formatter = opts[:formatter]
  @validator = opts[:validator] ||
    lambda { |v| v.respond_to?(:empty?) ? !v.empty? : !v.nil? }
  @compound = opts[:compound]
  @wants_array = opts.fetch(:wants_array,
    @compound || Constants::IN_NOT_IN.include?(@arel_predicate))
end

Public Instance Methods

==(other)
Alias for: eql?
eql?(other) click to toggle source
# File lib/ransack/predicate.rb, line 55
def eql?(other)
  self.class == other.class &&
  self.name == other.name
end
Also aliased as: ==
format(val) click to toggle source
# File lib/ransack/predicate.rb, line 65
def format(val)
  if formatter
    formatter.call(val)
  else
    val
  end
end
hash() click to toggle source
# File lib/ransack/predicate.rb, line 61
def hash
  name.hash
end
validate(vals, type = @type) click to toggle source
# File lib/ransack/predicate.rb, line 73
def validate(vals, type = @type)
  vals.any? { |v| validator.call(type ? v.cast(type) : v.value) }
end