Method: Parse::Constraint::RejectionConstraint#build

Defined in:
lib/parse/query/constraints.rb

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
# File 'lib/parse/query/constraints.rb', line 466

def build

  # if it's a hash, then it should be {:key=>"objectId", :query=>[]}
  remote_field_name = @operation.operand
  query = nil
  if @value.is_a?(Hash)
    res = @value.symbolize_keys
    remote_field_name = res[:key] || remote_field_name
    query = res[:query]
    unless query.is_a?(Parse::Query)
      raise ArgumentError, "Invalid Parse::Query object provided in :query field of value: #{@operation.operand}.#{$dontSelect} => #{@value}"
    end
    query = query.compile(encode: false, includeClassName: true)
  elsif @value.is_a?(Parse::Query)
    # if its a query, then assume dontSelect key is the same name as operand.
    query = @value.compile(encode: false, includeClassName: true)
  else
    raise ArgumentError, "Invalid `:reject` query constraint. It should follow the format: :field.reject => { key: 'key', query: '<Parse::Query>' }"
  end
  { @operation.operand => { :$dontSelect => { key: remote_field_name, query: query } } }
end