Class: DataMapper::Query::Conditions::AbstractOperation
- Inherits:
-
Object
- Object
- DataMapper::Query::Conditions::AbstractOperation
- Extended by:
- Equalizer
- Includes:
- Assertions, Enumerable
- Defined in:
- lib/dm-core/query/conditions/operation.rb
Overview
class Operation
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Set<AbstractOperation, AbstractComparison, Array>) operands
(also: #children)
readonly
Returns the child operations and comparisons.
-
- (AbstractOperation) parent
Returns the parent operation.
Class Method Summary (collapse)
-
+ (Set) descendants
private
Returns the classes that inherit from AbstractComparison.
-
+ (undefined) inherited(descendant)
private
Hook executed when inheriting from AbstractComparison.
-
+ (Symbol) slug(slug = nil)
Get and set the slug for the operation class.
Instance Method Summary (collapse)
-
- (self) <<(operand)
Add an operand to the operation.
-
- (self) clear
Clear the operands.
-
- (AndOperation) difference(other)
(also: #-)
Return the difference of the operation and another operand.
-
- (self) each {|operand| ... }
Iterate through each operand in the operation.
-
- (Boolean) empty?
Test to see if there are operands.
-
- (AbstractOperation, ...) first
Get the first operand.
-
- (AndOperation) intersection(other)
(also: #&)
Return the intersection of the operation and another operand.
-
- (self) merge(operands)
Add operands to the operation.
-
- (self) minimize
Minimize the operation.
-
- (Boolean) negated?
private
Test if the operation is negated.
-
- (Boolean) one?
Test to see if there is one operand.
-
- (Symbol) slug
private
Return the comparison class slug.
-
- (Array<AbstractOperation, AbstractComparison, Array>) sorted_operands
private
Return a list of operands in predictable order.
-
- (String) to_s
Return the string representation of the operation.
-
- (OrOperation) union(other)
(also: #|, #+)
Return the union with another operand.
-
- (Boolean) valid?
Test if the operation is valid.
Methods included from Equalizer
Methods included from Assertions
Instance Attribute Details
- (Set<AbstractOperation, AbstractComparison, Array>) operands (readonly) Also known as: children
Returns the child operations and comparisons
89 90 91 |
# File 'lib/dm-core/query/conditions/operation.rb', line 89 def operands @operands end |
- (AbstractOperation) parent
Returns the parent operation
81 82 83 |
# File 'lib/dm-core/query/conditions/operation.rb', line 81 def parent @parent end |
Class Method Details
+ (Set) descendants
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the classes that inherit from AbstractComparison
99 100 101 |
# File 'lib/dm-core/query/conditions/operation.rb', line 99 def self.descendants @descendants ||= DescendantSet.new end |
+ (undefined) inherited(descendant)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Hook executed when inheriting from AbstractComparison
108 109 110 111 |
# File 'lib/dm-core/query/conditions/operation.rb', line 108 def self.inherited(descendant) descendants << descendant super end |
+ (Symbol) slug(slug = nil)
Get and set the slug for the operation class
122 123 124 |
# File 'lib/dm-core/query/conditions/operation.rb', line 122 def self.slug(slug = nil) slug ? @slug = slug : @slug end |
Instance Method Details
- (self) <<(operand)
Add an operand to the operation
203 204 205 206 207 |
# File 'lib/dm-core/query/conditions/operation.rb', line 203 def <<(operand) assert_valid_operand_type(operand) @operands << relate_operand(operand) self end |
- (self) clear
Clear the operands
285 286 287 288 |
# File 'lib/dm-core/query/conditions/operation.rb', line 285 def clear @operands.clear self end |
- (AndOperation) difference(other) Also known as: -
Return the difference of the operation and another operand
263 264 265 |
# File 'lib/dm-core/query/conditions/operation.rb', line 263 def difference(other) Operation.new(:and, dup, Operation.new(:not, other.dup)).minimize end |
- (self) each {|operand| ... }
Iterate through each operand in the operation
159 160 161 162 |
# File 'lib/dm-core/query/conditions/operation.rb', line 159 def each @operands.each { |op| yield op } self end |
- (Boolean) empty?
Test to see if there are operands
170 171 172 |
# File 'lib/dm-core/query/conditions/operation.rb', line 170 def empty? @operands.empty? end |
- (AbstractOperation, ...) first
Get the first operand
142 143 144 145 |
# File 'lib/dm-core/query/conditions/operation.rb', line 142 def first each { |operand| return operand } nil end |
- (AndOperation) intersection(other) Also known as: &
Return the intersection of the operation and another operand
248 249 250 |
# File 'lib/dm-core/query/conditions/operation.rb', line 248 def intersection(other) Operation.new(:and, dup, other.dup).minimize end |
- (self) merge(operands)
Add operands to the operation
218 219 220 221 |
# File 'lib/dm-core/query/conditions/operation.rb', line 218 def merge(operands) operands.each { |op| self << op } self end |
- (self) minimize
Minimize the operation
275 276 277 |
# File 'lib/dm-core/query/conditions/operation.rb', line 275 def minimize self end |
- (Boolean) negated?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Test if the operation is negated
Defaults to return false.
308 309 310 311 |
# File 'lib/dm-core/query/conditions/operation.rb', line 308 def negated? parent = self.parent parent ? parent.negated? : false end |
- (Boolean) one?
Test to see if there is one operand
180 181 182 |
# File 'lib/dm-core/query/conditions/operation.rb', line 180 def one? @operands.size == 1 end |
- (Symbol) slug
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return the comparison class slug
132 133 134 |
# File 'lib/dm-core/query/conditions/operation.rb', line 132 def slug self.class.slug end |
- (Array<AbstractOperation, AbstractComparison, Array>) sorted_operands
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a list of operands in predictable order
319 320 321 |
# File 'lib/dm-core/query/conditions/operation.rb', line 319 def sorted_operands sort_by { |op| op.hash } end |
- (String) to_s
Return the string representation of the operation
296 297 298 |
# File 'lib/dm-core/query/conditions/operation.rb', line 296 def to_s empty? ? '' : "(#{sort_by { |op| op.to_s }.map { |op| op.to_s }.join(" #{slug.to_s.upcase} ")})" end |
- (OrOperation) union(other) Also known as: |, +
Return the union with another operand
232 233 234 |
# File 'lib/dm-core/query/conditions/operation.rb', line 232 def union(other) Operation.new(:or, dup, other.dup).minimize end |
- (Boolean) valid?
Test if the operation is valid
190 191 192 |
# File 'lib/dm-core/query/conditions/operation.rb', line 190 def valid? any? && all? { |op| valid_operand?(op) } end |