Class: Parse::Constraint::EndsWithConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- Parse::Constraint::EndsWithConstraint
- Defined in:
- lib/parse/query/constraints.rb
Overview
Equivalent to using the $regex Parse query operation with a suffix pattern.
This is useful for matching fields that end with a specific string.
Find files whose name ends with ".pdf"
File.where(:name.ends_with => ".pdf")
Generates: "name": { "$regex": "\.pdf$", "$options": "i" }
Instance Method Summary collapse
-
#build ⇒ Hash
The compiled constraint.
-
#ends_with ⇒ EndsWithConstraint
A registered method on a symbol to create the constraint.
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint.
2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 |
# File 'lib/parse/query/constraints.rb', line 2378 def build value = formatted_value unless value.is_a?(String) raise ArgumentError, "#{self.class}: Value must be a string for ends_with constraint" end # Validate length to prevent performance issues if value.length > Parse::RegexSecurity::MAX_PATTERN_LENGTH raise ArgumentError, "#{self.class}: Value too long (#{value.length} chars, max #{Parse::RegexSecurity::MAX_PATTERN_LENGTH})" end # Escape special regex characters in the suffix escaped_value = Regexp.escape(value) regex_pattern = "#{escaped_value}$" { @operation.operand => { :$regex => regex_pattern, :$options => "i" } } end |
#ends_with ⇒ EndsWithConstraint
A registered method on a symbol to create the constraint. Maps to Parse operator "$regex".
2374 |
# File 'lib/parse/query/constraints.rb', line 2374 constraint_keyword :$regex |