Sha256: fc9ff15431c0667b48f22a290eeefe350af3974d5d519fcccf9eea9beabe1fee

Contents?: true

Size: 1 KB

Versions: 4

Compression:

Stored size: 1 KB

Contents

require 'ransack/constants'
require 'ransack/predicate'

module Ransack
  module Configuration

    mattr_accessor :predicates, :options
    self.predicates = {}
    self.options = {
        search_key: :q
    }

    def configure
      yield self
    end

    def add_predicate(name, opts = {})
      name = name.to_s
      opts[:name] = name
      compounds = opts.delete(:compounds)
      compounds = true if compounds.nil?
      compounds = false if opts[:wants_array]
      opts[:arel_predicate] = opts[:arel_predicate].to_s

      self.predicates[name] = Predicate.new(opts)

      ['_any', '_all'].each do |suffix|
        self.predicates[name + suffix] = Predicate.new(
          opts.merge(
            name: name + suffix,
            arel_predicate: opts[:arel_predicate] + suffix,
            compound: true
          )
        )
      end if compounds
    end

    # default search_key that, it can be overridden on sort_link level
    def search_key=(name)
      self.options[:search_key] = name
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ransack-1.2.3 lib/ransack/configuration.rb
ransack-1.2.2 lib/ransack/configuration.rb
ransack-1.2.1 lib/ransack/configuration.rb
ransack-1.2.0 lib/ransack/configuration.rb