Module: Positionable::EvalSupport

Defined in:
lib/positionable.rb

Class Method Summary collapse

Class Method Details

.array_conditions_to_eval(conditions) ⇒ Object



67
68
69
# File 'lib/positionable.rb', line 67

def array_conditions_to_eval(conditions)
  string_conditions_to_eval ActiveRecord::Base.send(:sanitize_sql_array, conditions)
end

.conditions_to_eval(conditions) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/positionable.rb', line 59

def conditions_to_eval(conditions)
  case conditions
    when Array  then array_conditions_to_eval(conditions)
    when Hash   then hash_conditions_to_eval(conditions)
    when String then string_conditions_to_eval(conditions)
  end
end

.hash_conditions_to_eval(conditions) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/positionable.rb', line 71

def hash_conditions_to_eval(conditions)
  conditions.inject("") do |str, (attribute, value)|
    str << ' && ' unless str.blank?
    str << "#{attribute} == "
    str << case value
      when String then "\'#{value}\'"
      when nil then 'nil'
      else value.to_s
    end
  end
end

.string_conditions_to_eval(conditions) ⇒ Object



83
84
85
# File 'lib/positionable.rb', line 83

def string_conditions_to_eval(conditions)
  conditions.gsub(' = ', ' == ').gsub(/ and /i, ' && ').gsub(/ or /i, ' || ')
end