Class: DataMapper::Query::Conditions::AndOperation

Inherits:
AbstractOperation show all
Includes:
FlattenOperation
Defined in:
lib/dm-core/query/conditions/operation.rb

Overview

module FlattenOperation

Instance Attribute Summary

Attributes inherited from AbstractOperation

#operands, #parent

Instance Method Summary collapse

Methods included from FlattenOperation

#<<

Methods inherited from AbstractOperation

#<<, #clear, descendants, #difference, #each, #empty?, #first, inherited, #intersection, #merge, #negated?, #one?, slug, #slug, #sorted_operands, #to_s, #union, #valid?

Methods included from Equalizer

#equalize

Methods included from Assertions

#assert_kind_of

Instance Method Details

#matches?(record) ⇒ true

Match the record

Examples:

with a Hash

operation.matches?({ :id => 1 })  # => true

with a Resource

operation.matches?(Blog::Article.new(:id => 1))  # => true


461
462
463
# File 'lib/dm-core/query/conditions/operation.rb', line 461

def matches?(record)
  all? { |op| op.respond_to?(:matches?) ? op.matches?(record) : true }
end

#minimizeself, ...

Minimize the operation



473
474
475
476
477
478
479
480
481
# File 'lib/dm-core/query/conditions/operation.rb', line 473

def minimize
  minimize_operands

  return Operation.new(:null) if any? && all? { |op| op.nil? }

  prune_operands

  one? ? first : self
end