Class: Parse::Query::Condition

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/query.rb

Instance Method Summary collapse

Constructor Details

#initialize(query, column_name) ⇒ Condition

Returns a new instance of Condition.



167
168
169
170
171
# File 'lib/parse/query.rb', line 167

def initialize query, column_name
  @query = query
  @column_name = column_name
  @conditions = []
end

Instance Method Details

#exists(val = true) ⇒ Object



199
200
201
202
# File 'lib/parse/query.rb', line 199

def exists val=true
  @conditions.push ['$exists', val]
  self
end

#or(cond) ⇒ Object



226
227
228
229
230
231
232
233
# File 'lib/parse/query.rb', line 226

def or cond
  # quite dirty!!
  @query.where.delete self
  @query.where.delete cond
  or_cond = Condition.new @query, '$or'
  or_cond.eq [self, cond]
  @query.where.push or_cond
end

#to_sObject



235
236
237
238
239
240
241
242
243
244
# File 'lib/parse/query.rb', line 235

def to_s
  if @conditions.size == 1 && !@conditions[0].is_a?(Array)
    "#{@column_name.to_s.inspect}:#{condition_to_s @conditions[0]}"
  elsif @conditions.size == 1 && @conditions[0][0].to_s[0] != '$'
    # $or
    "#{@column_name.to_s.inspect}:#{condition_to_s @conditions[0]}"
  else
    "#{@column_name.to_s.inspect}:{#{@conditions.map{|c| condition_to_s c}.join ','}}"
  end
end