Module: Ransack::Configuration

Included in:
Ransack
Defined in:
lib/ransack/configuration.rb

Instance Method Summary collapse

Instance Method Details

#add_predicate(name, opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ransack/configuration.rb', line 18

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]

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

  Ransack::Constants::SUFFIXES.each do |suffix|
    compound_name = name + suffix
    self.predicates[compound_name] = Predicate.new(
      opts.merge(
        :name => compound_name,
        :arel_predicate => arel_predicate_with_suffix(
          opts[:arel_predicate], suffix
          ),
        :compound => true
      )
    )
  end if compounds
end

#arel_predicate_with_suffix(arel_predicate, suffix) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/ransack/configuration.rb', line 52

def arel_predicate_with_suffix(arel_predicate, suffix)
  if arel_predicate === Proc
    proc { |v| "#{arel_predicate.call(v)}#{suffix}" }
  else
    "#{arel_predicate}#{suffix}"
  end
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



14
15
16
# File 'lib/ransack/configuration.rb', line 14

def configure
  yield self
end

#ignore_unknown_conditions=(boolean) ⇒ Object

raise an error if an unknown predicate, condition or attribute is passed into a search



48
49
50
# File 'lib/ransack/configuration.rb', line 48

def ignore_unknown_conditions=(boolean)
  self.options[:ignore_unknown_conditions] = boolean
end

#search_key=(name) ⇒ Object

default search_key that, it can be overridden on sort_link level



42
43
44
# File 'lib/ransack/configuration.rb', line 42

def search_key=(name)
  self.options[:search_key] = name
end