class RansackCondition

Attributes

attribute[RW]
id[RW]
predicate[RW]
value[RW]

Public Class Methods

new(attributes={}) { |self| ... } click to toggle source
# File lib/ransack_condition.rb, line 4
def initialize(attributes={})
  @id = RansackQuery.generate_id
  @predicate = attributes[:predicate] || :eq
  @attribute = attributes[:attribute]
  @value = attributes[:value]
  yield self if block_given?
end

Public Instance Methods

ransackify() click to toggle source
# File lib/ransack_condition.rb, line 12
def ransackify
  {
      @id => {
          'a' => build_ransack_array(@attribute, 'name'),
          'p' => @predicate.to_s,
          'v' => build_ransack_array(@value, 'value')
      }
  }
end
to_condition() click to toggle source
# File lib/ransack_condition.rb, line 22
def to_condition
  self
end

Private Instance Methods

build_ransack_array(array, hash_key) click to toggle source
# File lib/ransack_condition.rb, line 27
def build_ransack_array(array, hash_key)
  counter = -1
  [array].flatten.reduce({}) do |result, attribute|
    counter += 1
    result.merge({
                     counter.to_s => {
                         hash_key => attribute
                     }
                 })
  end
end