Class: Parse::Operation
- Inherits:
- Object
- Object
- Parse::Operation
- Defined in:
- lib/parse/query/operation.rb
Overview
An operation is the core part of Constraint when performing queries. It contains an operand (the Parse field) and an operator (the Parse operation). These combined with a value, provide you with a constraint.
All operation registrations add methods to the Symbol class.
Class Attribute Summary collapse
- .operators ⇒ Hash
to their Constraint subclass.
Instance Attribute Summary collapse
- #operand ⇒ Symbol
The field in Parse for this operation.
- #operator ⇒ Symbol
The type of Parse operation.
Class Method Summary collapse
- .register(op, klass) ⇒ Object
Register a new symbol operator method mapped to a specific Constraint.
Instance Method Summary collapse
- #constraint(value = nil) ⇒ Parse::Constraint
Create a new constraint based on the handler that had been registered with this operation.
- #handler ⇒ Parse::Constraint
The constraint class designed to handle this operator.
- #initialize(field, op) ⇒ Operation constructor
Create a new operation.
- #valid? ⇒ Boolean
Whether this operation is defined properly.
Constructor Details
#initialize(field, op) ⇒ Operation
Create a new operation.
51 52 53 54 55 | # File 'lib/parse/query/operation.rb', line 51 def initialize(field, op) self.operand = field.to_sym self.operand = :objectId if operand == :id self.operator = op.to_sym end |
Class Attribute Details
.operators ⇒ Hash
to their Constraint subclass.
30 31 32 | # File 'lib/parse/query/operation.rb', line 30 def operators @operators end |
Instance Attribute Details
#operand ⇒ Symbol
The field in Parse for this operation.
20 21 22 | # File 'lib/parse/query/operation.rb', line 20 def operand @operand end |
#operator ⇒ Symbol
The type of Parse operation.
25 26 27 | # File 'lib/parse/query/operation.rb', line 25 def operator @operator end |
Class Method Details
.register(op, klass) ⇒ Object
Register a new symbol operator method mapped to a specific Constraint.
71 72 73 74 75 76 77 | # File 'lib/parse/query/operation.rb', line 71 def self.register(op, klass) Operation.operators[op.to_sym] = klass Symbol.send :define_method, op do |value = nil| operation = Operation.new self, op value.nil? ? operation : operation.constraint(value) end end |
Instance Method Details
#constraint(value = nil) ⇒ Parse::Constraint
Create a new constraint based on the handler that had been registered with this operation.
66 67 68 | # File 'lib/parse/query/operation.rb', line 66 def constraint(value = nil) handler.new(self, value) end |
#handler ⇒ Parse::Constraint
Returns the constraint class designed to handle this operator.
44 45 46 | # File 'lib/parse/query/operation.rb', line 44 def handler Operation.operators[@operator] unless @operator.nil? end |
#valid? ⇒ Boolean
Whether this operation is defined properly.
38 39 40 | # File 'lib/parse/query/operation.rb', line 38 def valid? ! (@operand.nil? || @operator.nil? || handler.nil?) end |