Included Modules

Class Index [+]

Quicksearch

DataMapper::Query::Conditions::AbstractOperation

Attributes

parent[RW]

Returns the parent operation

@return [AbstractOperation]

  the parent operation

@api semipublic

operands[R]

Returns the child operations and comparisons

@return [Set<AbstractOperation, AbstractComparison, Array>]

  the set of operations and comparisons

@api semipublic

Public Class Methods

descendants() click to toggle source

Returns the classes that inherit from AbstractComparison

@return [Set]

  the descendant classes

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 99
 99:         def self.descendants
100:           @descendants ||= DescendantSet.new
101:         end
inherited(descendant) click to toggle source

Hook executed when inheriting from AbstractComparison

@return [undefined]

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 108
108:         def self.inherited(descendant)
109:           descendants << descendant
110:         end
new(*operands) click to toggle source

Initialize an operation

@param [Array<AbstractOperation, AbstractComparison, Array>] *operands

  the operands to include in the operation

@return [AbstractOperation]

  the operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 333
333:         def initialize(*operands)
334:           @operands = Set.new
335:           merge(operands)
336:         end
slug(slug = nil) click to toggle source

Get and set the slug for the operation class

@param [Symbol] slug

  optionally set the slug for the operation class

@return [Symbol]

  the slug for the operation class

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 121
121:         def self.slug(slug = nil)
122:           slug ? @slug = slug : @slug
123:         end

Public Instance Methods

&(other) click to toggle source
Alias for: intersection
+(other) click to toggle source
Alias for: union
-(other) click to toggle source
Alias for: difference
<<(operand) click to toggle source

Add an operand to the operation

@param [AbstractOperation, AbstractComparison, Array] operand

  the operand to add

@return [self]

  the operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 202
202:         def <<(operand)
203:           assert_valid_operand_type(operand)
204:           @operands << relate_operand(operand)
205:           self
206:         end
clear() click to toggle source

Clear the operands

@return [self]

  the operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 284
284:         def clear
285:           @operands.clear
286:           self
287:         end
difference(other) click to toggle source

Return the difference of the operation and another operand

@param [AbstractOperation] other

  the operand to not match

@return [AndOperation]

  the intersection of the operation and operand

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 262
262:         def difference(other)
263:           Operation.new(:and, dup, Operation.new(:not, other.dup)).minimize
264:         end
Also aliased as: -
each() click to toggle source

Iterate through each operand in the operation

@yield [operand]

  yields to each operand

@yieldparam [AbstractOperation, AbstractComparison, Array] operand

  each operand

@return [self]

  returns the operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 158
158:         def each
159:           @operands.each { |op| yield op }
160:           self
161:         end
empty?() click to toggle source

Test to see if there are operands

@return [Boolean]

  returns true if there are operands

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 169
169:         def empty?
170:           @operands.empty?
171:         end
first() click to toggle source

Get the first operand

@return [AbstractOperation, AbstractComparison, Array]

  returns the first operand

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 141
141:         def first
142:           each { |operand| return operand }
143:           nil
144:         end
intersection(other) click to toggle source

Return the intersection of the operation and another operand

@param [AbstractOperation] other

  the operand to intersect with

@return [AndOperation]

  the intersection of the operation and operand

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 247
247:         def intersection(other)
248:           Operation.new(:and, dup, other.dup).minimize
249:         end
Also aliased as: &
merge(operands) click to toggle source

Add operands to the operation

@param [#] operands

  the operands to add

@return [self]

  the operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 217
217:         def merge(operands)
218:           operands.each { |op| self << op }
219:           self
220:         end
minimize() click to toggle source

Minimize the operation

@return [self]

  the minimized operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 274
274:         def minimize
275:           self
276:         end
negated?() click to toggle source

Test if the operation is negated

Defaults to return false.

@return [Boolean]

  true if the operation is negated, false if not

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 307
307:         def negated?
308:           parent = self.parent
309:           parent ? parent.negated? : false
310:         end
one?() click to toggle source

Test to see if there is one operand

@return [Boolean]

  true if there is only one operand

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 179
179:         def one?
180:           @operands.size == 1
181:         end
slug() click to toggle source

Return the comparison class slug

@return [Symbol]

  the comparison class slug

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 131
131:         def slug
132:           self.class.slug
133:         end
sorted_operands() click to toggle source

Return a list of operands in predictable order

@return [Array<AbstractOperation, AbstractComparison, Array>]

  list of operands sorted in deterministic order

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 318
318:         def sorted_operands
319:           sort_by { |op| op.hash }
320:         end
to_s() click to toggle source

Return the string representation of the operation

@return [String]

  the string representation of the operation

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 295
295:         def to_s
296:           empty? ? '' : "(#{sort_by { |op| op.to_s }.map { |op| op.to_s }.join(" #{slug.to_s.upcase} ")})"
297:         end
union(other) click to toggle source

Return the union with another operand

@param [AbstractOperation] other

  the operand to union with

@return [OrOperation]

  the union of the operation and operand

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 231
231:         def union(other)
232:           Operation.new(:or, dup, other.dup).minimize
233:         end
Also aliased as: |, +
valid?() click to toggle source

Test if the operation is valid

@return [Boolean]

  true if the operation is valid, false if not

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 189
189:         def valid?
190:           any? && all? { |op| valid_operand?(op) }
191:         end
|(other) click to toggle source
Alias for: union

Private Instance Methods

assert_valid_operand_type(operand) click to toggle source

Assert that the operand is a valid type

@param [AbstractOperation, AbstractComparison, Array] operand

  the operand to test

@return [undefined]

@raise [ArgumentError]

  raised if the operand is not a valid type

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 410
410:         def assert_valid_operand_type(operand)
411:           assert_kind_of 'operand', operand, AbstractOperation, AbstractComparison, Array
412:         end
initialize_copy(*) click to toggle source

Copy an operation

@param [AbstractOperation] original

  the original operation

@return [undefined]

@api semipublic

     # File lib/dm-core/query/conditions/operation.rb, line 346
346:         def initialize_copy(*)
347:           @operands = map { |op| op.dup }.to_set
348:         end
minimize_operands() click to toggle source

Minimize the operands recursively

@return [undefined]

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 355
355:         def minimize_operands
356:           # FIXME: why does Set#map! not work here?
357:           @operands = map do |op|
358:             relate_operand(op.respond_to?(:minimize) ? op.minimize : op)
359:           end.to_set
360:         end
prune_operands() click to toggle source

Prune empty operands recursively

@return [undefined]

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 367
367:         def prune_operands
368:           @operands.delete_if { |op| op.respond_to?(:empty?) ? op.empty? : false }
369:         end
relate_operand(operand) click to toggle source

Set self to be the operand’s parent

@return [AbstractOperation, AbstractComparison, Array]

  the operand that was related to self

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 394
394:         def relate_operand(operand)
395:           operand.parent = self if operand.respond_to?(:parent=)
396:           operand
397:         end
valid_operand?(operand) click to toggle source

Test if the operand is valid

@param [AbstractOperation, AbstractComparison, Array] operand

  the operand to test

@return [Boolean]

  true if the operand is valid

@api private

     # File lib/dm-core/query/conditions/operation.rb, line 380
380:         def valid_operand?(operand)
381:           if operand.respond_to?(:valid?)
382:             operand.valid?
383:           else
384:             true
385:           end
386:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.