Class: DataMapper::Query::Conditions::AbstractOperation

### Home Classes Methods

### In Files

- lib/dm-core/query/conditions/operation.rb

### Parent

Object

### Methods

- ::descendants
- ::inherited
- ::new
- ::slug
- #&
- #+
- #-
- #<<
- #clear
- #difference
- #each
- #empty?
- #first
- #intersection
- #merge
- #minimize
- #negated?
- #one?
- #slug
- #sorted_operands
- #to_s
- #union
- #valid?
- #|

### Included Modules

- DataMapper::Assertions
- Enumerable

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::Adapters
- DataMapper::Adapters::AbstractAdapter
- DataMapper::Adapters::InMemoryAdapter
- DataMapper::Assertions
- DataMapper::Associations
- DataMapper::Associations::ManyToMany
- DataMapper::Associations::ManyToMany::Collection
- DataMapper::Associations::ManyToMany::Relationship
- DataMapper::Associations::ManyToOne
- DataMapper::Associations::ManyToOne::Relationship
- DataMapper::Associations::OneToMany
- DataMapper::Associations::OneToMany::Collection
- DataMapper::Associations::OneToMany::Relationship
- DataMapper::Associations::OneToOne
- DataMapper::Associations::OneToOne::Relationship
- DataMapper::Associations::Relationship
- DataMapper::Chainable
- DataMapper::Collection
- DataMapper::Deprecate
- DataMapper::DescendantSet
- DataMapper::Equalizer
- DataMapper::Ext
- DataMapper::Ext::Array
- DataMapper::Ext::Hash
- DataMapper::Ext::Module
- DataMapper::Ext::Object
- DataMapper::Ext::String
- DataMapper::Hook
- DataMapper::Hook::ClassMethods
- DataMapper::IdentityMap
- DataMapper::ImmutableDeletedError
- DataMapper::ImmutableError
- DataMapper::IncompleteModelError
- DataMapper::Inflector
- DataMapper::Inflector::Inflections
- DataMapper::LocalObjectSpace
- DataMapper::Logger
- DataMapper::Mash
- DataMapper::Model
- DataMapper::Model::Hook
- DataMapper::Model::Hook::MethodCommand
- DataMapper::Model::Hook::Methods
- DataMapper::Model::Hook::ProcCommand
- DataMapper::Model::Is
- DataMapper::Model::Property
- DataMapper::Model::Relationship
- DataMapper::Model::Scope
- DataMapper::NamingConventions
- DataMapper::NamingConventions::Field
- DataMapper::NamingConventions::Field::Underscored
- DataMapper::NamingConventions::Field::UnderscoredAndPluralized
- DataMapper::NamingConventions::Field::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Field::Yaml
- DataMapper::NamingConventions::Resource
- DataMapper::NamingConventions::Resource::Underscored
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralized
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutLeadingModule
- DataMapper::NamingConventions::Resource::UnderscoredAndPluralizedWithoutModule
- DataMapper::NamingConventions::Resource::Yaml
- DataMapper::ObjectNotFoundError
- DataMapper::OrderedSet
- DataMapper::OrderedSet::Cache
- DataMapper::OrderedSet::Cache::API
- DataMapper::PersistenceError
- DataMapper::PluginNotFoundError
- DataMapper::Property
- DataMapper::Property::Binary
- DataMapper::Property::Boolean
- DataMapper::Property::Class
- DataMapper::Property::Date
- DataMapper::Property::DateTime
- DataMapper::Property::Decimal
- DataMapper::Property::Discriminator
- DataMapper::Property::Discriminator::Model
- DataMapper::Property::Float
- DataMapper::Property::Integer
- DataMapper::Property::Lookup
- DataMapper::Property::Numeric
- DataMapper::Property::Object
- DataMapper::Property::PassThroughLoadDump
- DataMapper::Property::Serial
- DataMapper::Property::String
- DataMapper::Property::Text
- DataMapper::Property::Time
- DataMapper::Property::Typecast
- DataMapper::Property::Typecast::Numeric
- DataMapper::Property::Typecast::Time
- DataMapper::PropertySet
- DataMapper::Query
- DataMapper::Query::Conditions
- DataMapper::Query::Conditions::AbstractComparison
- DataMapper::Query::Conditions::AbstractOperation
- DataMapper::Query::Conditions::AndOperation
- DataMapper::Query::Conditions::Comparison
- DataMapper::Query::Conditions::EqualToComparison
- DataMapper::Query::Conditions::FlattenOperation
- DataMapper::Query::Conditions::GreaterThanComparison
- DataMapper::Query::Conditions::GreaterThanOrEqualToComparison
- DataMapper::Query::Conditions::InclusionComparison
- DataMapper::Query::Conditions::LessThanComparison
- DataMapper::Query::Conditions::LessThanOrEqualToComparison
- DataMapper::Query::Conditions::LikeComparison
- DataMapper::Query::Conditions::NotOperation
- DataMapper::Query::Conditions::NullOperation
- DataMapper::Query::Conditions::Operation
- DataMapper::Query::Conditions::OrOperation
- DataMapper::Query::Conditions::RegexpComparison
- DataMapper::Query::Conditions::RelationshipHandler
- DataMapper::Query::Direction
- DataMapper::Query::Operator
- DataMapper::Query::Path
- DataMapper::Query::Sort
- DataMapper::RelationshipSet
- DataMapper::Repository
- DataMapper::RepositoryNotSetupError
- DataMapper::Resource
- DataMapper::Resource::PersistenceState
- DataMapper::Resource::PersistenceState::Clean
- DataMapper::Resource::PersistenceState::Deleted
- DataMapper::Resource::PersistenceState::Dirty
- DataMapper::Resource::PersistenceState::Immutable
- DataMapper::Resource::PersistenceState::Persisted
- DataMapper::Resource::PersistenceState::Transient
- DataMapper::SaveFailureError
- DataMapper::Spec
- DataMapper::Spec::Adapters
- DataMapper::Spec::Adapters::Adapter
- DataMapper::Spec::Adapters::Helpers
- DataMapper::Spec::Adapters::InMemoryAdapter
- DataMapper::Spec::CollectionHelpers
- DataMapper::Spec::CollectionHelpers::GroupMethods
- DataMapper::Spec::Helpers
- DataMapper::Spec::PendingHelpers
- DataMapper::Subject
- DataMapper::SubjectSet
- DataMapper::SubjectSet::NameCache
- DataMapper::Undefined
- DataMapper::UnknownRelationshipError
- DataMapper::UnsavedParentError
- DataMapper::UpdateConflictError
- Blog
- Blog::Article
- ChildSubType
- CounterAdapter
- Heffalump
- Kernel
- LazyArray
- Object
- OtherComparison
- Pathname
- SubType
- Symbol

No matching classes.

# DataMapper::Query::Conditions::AbstractOperation

### Attributes

children[R]

Returns the child operations and comparisons

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

    the set of operations and comparisons

@api semipublic

operands[R]

Returns the child operations and comparisons

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

    the set of operations and comparisons

@api semipublic

parent[RW]

Returns the parent operation

@return [AbstractOperation]

    the parent operation

@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
    def self.descendants
      @descendants ||= DescendantSet.new
    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
    def self.inherited(descendant)
      descendants << descendant
    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
    def initialize(*operands)
      @operands = Set.new
      merge(operands)
    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
    def self.slug(slug = nil)
      slug ? @slug = slug : @slug
    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
    def <<(operand)
      assert_valid_operand_type(operand)
      @operands << relate_operand(operand)
      self
    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
    def clear
      @operands.clear
      self
    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
    def difference(other)
      Operation.new(:and, dup, Operation.new(:not, other.dup)).minimize
    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
    def each
      @operands.each { |op| yield op }
      self
    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
    def empty?
      @operands.empty?
    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
    def first
      each { |operand| return operand }
      nil
    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
    def intersection(other)
      Operation.new(:and, dup, other.dup).minimize
    end

Also aliased as: &
merge(operands) click to toggle source

Add operands to the operation

@param [each] operands

    the operands to add

@return [self]

    the operation

@api semipublic

    # File lib/dm-core/query/conditions/operation.rb, line 217
    def merge(operands)
      operands.each { |op| self << op }
      self
    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
    def minimize
      self
    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
    def negated?
      parent = self.parent
      parent ? parent.negated? : false
    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
    def one?
      @operands.size == 1
    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
    def slug
      self.class.slug
    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
    def sorted_operands
      sort_by { |op| op.hash }
    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
    def to_s
      empty? ? '' : "(#{sort_by { |op| op.to_s }.map { |op| op.to_s }.join(" #{slug.to_s.upcase} ")})"
    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
    def union(other)
      Operation.new(:or, dup, other.dup).minimize
    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
    def valid?
      any? && all? { |op| valid_operand?(op) }
    end

|(other) click to toggle source
Alias for: union

[Validate]

Generated with the Darkfish Rdoc Generator 2.