Class: Parse::Constraint::RegularExpressionConstraint
- Inherits:
-
Parse::Constraint
- Object
- Parse::Constraint
- Parse::Constraint::RegularExpressionConstraint
- Defined in:
- lib/parse/query/constraints.rb
Overview
Equivalent to the ‘$regex` Parse query operation. Requires that a field value match a regular expression.
q.where :field.like => /ruby_regex/i
:name.like => /Bob/i
Instance Attribute Summary
Attributes inherited from Parse::Constraint
#operand, #operation, #operator, #value
Instance Method Summary collapse
-
#build ⇒ Hash
Builds the regex constraint with security validation.
-
#like ⇒ RegularExpressionConstraint
A registered method on a symbol to create the constraint.
-
#regex ⇒ RegularExpressionConstraint
Alias for #like.
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
#build ⇒ Hash
Builds the regex constraint with security validation.
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 |
# File 'lib/parse/query/constraints.rb', line 1632 def build value = formatted_value pattern_str = value.is_a?(Regexp) ? value.source : value.to_s = value.is_a?(Regexp) && value.casefold? ? "i" : nil # Validate the regex pattern for ReDoS vulnerabilities Parse::RegexSecurity.validate!(pattern_str) if { @operation.operand => { key => pattern_str, :$options => } } else { @operation.operand => { key => pattern_str } } end end |
#like ⇒ RegularExpressionConstraint
A registered method on a symbol to create the constraint. Maps to Parse operator “$regex”.
|
|
# File 'lib/parse/query/constraints.rb', line 1616
|
#regex ⇒ RegularExpressionConstraint
Alias for #like
1625 |
# File 'lib/parse/query/constraints.rb', line 1625 constraint_keyword :$regex |