Sha256: 646e2b539568287ba173bf01f29efbe06ec03c39fe305b6e48a235ef67aeb518

Contents?: true

Size: 1.77 KB

Versions: 20

Compression:

Stored size: 1.77 KB

Contents

module Ransack
  module Constants
    TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].to_set
    FALSE_VALUES = [false, 0, '0', 'f', 'F', 'false', 'FALSE'].to_set

    AREL_PREDICATES = %w(eq not_eq matches does_not_match lt lteq gt gteq in not_in)

    DERIVED_PREDICATES = [
      ['cont', {:arel_predicate => 'matches', :formatter => proc {|v| "%#{v}%"}}],
      ['not_cont', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "%#{v}%"}}],
      ['start', {:arel_predicate => 'matches', :formatter => proc {|v| "#{v}%"}}],
      ['not_start', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "#{v}%"}}],
      ['end', {:arel_predicate => 'matches', :formatter => proc {|v| "%#{v}"}}],
      ['not_end', {:arel_predicate => 'does_not_match', :formatter => proc {|v| "%#{v}"}}],
      ['true', {:arel_predicate => 'eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}}],
      ['false', {:arel_predicate => 'eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| !v}}],
      ['present', {:arel_predicate => 'not_eq_all', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| [nil, '']}}],
      ['blank', {:arel_predicate => 'eq_any', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| [nil, '']}}],
      ['null', {:arel_predicate => 'eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| nil}}],
      ['not_null', {:arel_predicate => 'not_eq', :compounds => false, :type => :boolean, :validator => proc {|v| TRUE_VALUES.include?(v)}, :formatter => proc {|v| nil}}]
    ]
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
ransack_ffcrm-0.7.1 lib/ransack/constants.rb
ransack-0.7.0 lib/ransack/constants.rb
ransack_ffcrm-0.6.0 lib/ransack/constants.rb
ransack-0.6.0 lib/ransack/constants.rb
ransack-0.5.8 lib/ransack/constants.rb
ransack-0.5.7 lib/ransack/constants.rb
ransack-0.5.6 lib/ransack/constants.rb
ransack-0.5.5 lib/ransack/constants.rb
ransack-0.5.4 lib/ransack/constants.rb
ransack-0.5.3 lib/ransack/constants.rb
ransack-0.5.2 lib/ransack/constants.rb
ransack-0.5.1 lib/ransack/constants.rb
ransack-0.5.0 lib/ransack/constants.rb
ransack-0.4.2 lib/ransack/constants.rb
ransack-0.4.1 lib/ransack/constants.rb
ransack-0.4.0 lib/ransack/constants.rb
ransack-0.3.0 lib/ransack/constants.rb
ransack-0.2.1 lib/ransack/constants.rb
ransack-0.2.0 lib/ransack/constants.rb
ransack-0.1.0 lib/ransack/constants.rb