Class: Parse::Constraint::EmptyConstraint

Inherits:
Parse::Constraint show all
Defined in:
lib/parse/query/constraints.rb

Overview

Checks whether an array field contains any elements

q.where :field.empty => true

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, constraint_keyword, create, formatted_value, #formatted_value, #initialize, #key, #precedence, register, #to_s

Constructor Details

This class inherits a constructor from Parse::Constraint

Instance Method Details

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



356
357
358
359
360
361
362
363
364
365
# File 'lib/parse/query/constraints.rb', line 356

def build
  # if nullability is equal true, then $empty should be set to false
  value = formatted_value

  unless value == true || value == false
    raise ArgumentError, "#{self.class}: Non-Boolean value passed, it must be either `true` or `false`"
  end

  return { "#{@operation.operand}.0" => { key => !value } }
end

#emptyExistsConstraint

A registered method on a symbol to create the constraint.

Examples:

q.where :field.empty => true

Returns:



352
# File 'lib/parse/query/constraints.rb', line 352

constraint_keyword :$exists