class Ransack::Predicate
Attributes
Public Class Methods
Source
# File lib/ransack/predicate.rb, line 16 def detect_and_strip_from_string!(str) detect_from_string str, chomp: true end
Source
# File lib/ransack/predicate.rb, line 20 def detect_from_string(str, chomp: false) return unless str Ransack.predicates.sorted_names_with_underscores.each do |predicate, underscored| if str.end_with? underscored str.chomp! underscored if chomp return predicate end end nil end
Source
# File lib/ransack/predicate.rb, line 12 def named(name) Ransack.predicates[(name || Ransack.options[:default_predicate]).to_s] end
Source
# File lib/ransack/predicate.rb, line 35 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)) @case_insensitive = opts[:case_insensitive] end
Public Instance Methods
Source
# File lib/ransack/predicate.rb, line 48 def eql?(other) self.class == other.class && self.name == other.name end
Also aliased as: ==
Source
# File lib/ransack/predicate.rb, line 58 def format(val) if formatter formatter.call(val) else val end end
Source
# File lib/ransack/predicate.rb, line 70 def negative? @name.include?("not_".freeze) end
Source
# File lib/ransack/predicate.rb, line 66 def validate(vals, type = @type) vals.any? { |v| validator.call(type ? v.cast(type) : v.value) } end