Class: DataMapper::Query::Conditions::AbstractComparison

### Home Classes Methods

### In Files

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

### Parent

Object

### Methods

- ::descendants
- ::inherited
- ::new
- ::slug
- #inspect
- #matches?
- #negated?
- #property?
- #relationship?
- #slug
- #to_s
- #valid?
- #value

### 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::AbstractComparison

A base class for the various comparison classes.

### Attributes

loaded_value[R]

The loaded/typecast value

In the case of primitive types, this will be the same as `value`, however when using primitive property this stores the loaded value.

If writing an adapter, you should use `value`, while plugin authors should refer to `loaded_value`.

@return [Object]

@api semipublic

parent[RW]

@api semipublic

subject[R]

The property or relationship which is being matched against

@return [Property, Associations::Relationship]

@api semipublic

### Public Class Methods

descendants() click to toggle source

Keeps track of AbstractComparison subclasses (used in Comparison)

@return [Set<AbstractComparison>] @api private

    # File lib/dm-core/query/conditions/comparison.rb, line 159
    def self.descendants
      @descendants ||= DescendantSet.new
    end

inherited(descendant) click to toggle source

Registers AbstractComparison subclasses (used in Comparison)

@api private

    # File lib/dm-core/query/conditions/comparison.rb, line 166
    def self.inherited(descendant)
      descendants << descendant
    end

new(subject, value) click to toggle source

Creates a new AbstractComparison instance with `subject` and `value`

@param [Property, Associations::Relationship] subject

    The subject of the comparison - the value of the subject will be
    matched against the given value parameter.

@param [Object] value

    The value for the comparison.

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 289
    def initialize(subject, value)
      @subject      = subject
      @loaded_value = typecast(value)
      @dumped_value = dump
    end

slug(slug = nil) click to toggle source

Setter/getter: allows subclasses to easily set their slug

@param [Symbol] slug

    The slug to be set for this class. Passing nil returns the current
    value instead.

@return [Symbol]

    The current slug set for the Comparison.

@example Creating a MyComparison compairson with slug :exact.

    class MyComparison < AbstractComparison
      slug :exact
    end

@api semipublic

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

### Public Instance Methods

inspect() click to toggle source

Returns a human-readable representation of this object

@return [String]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 251
    def inspect
      "#<#{self.class} @subject=#{@subject.inspect} "              "@dumped_value=#{@dumped_value.inspect} @loaded_value=#{@loaded_value.inspect}>"
    end

matches?(record) click to toggle source

Test that the record value matches the comparison

@param [Resource, Hash] record

    The record containing the value to be matched

@return [Boolean]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 207
    def matches?(record)
      match_property?(record)
    end

negated?() click to toggle source

@api private

    # File lib/dm-core/query/conditions/comparison.rb, line 270
    def negated?
      parent = self.parent
      parent ? parent.negated? : false
    end

property?() click to toggle source

Returns whether the subject is a Property

@return [Boolean]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 242
    def property?
      subject.kind_of?(Property)
    end

relationship?() click to toggle source

Returns whether the subject is a Relationship

@return [Boolean]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 233
    def relationship?
      false
    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/comparison.rb, line 195
    def slug
      self.class.slug
    end

to_s() click to toggle source

Returns a string version of this Comparison object

@example

    Comparison.new(:==, MyClass.my_property, "value")
    # => "my_property == value"

@return [String]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 265
    def to_s
      "#{subject.name} #{comparator_string} #{dumped_value.inspect}"
    end

valid?() click to toggle source

Tests that the Comparison is valid

Subclasses can overload this to customise the means by which they determine the validity of the comparison. valid? is called prior to performing a query on the repository: each Comparison within a Query must be valid otherwise the query will not be performed.

@see DataMapper::Property#valid? @see DataMapper::Associations::Relationship#valid?

@return [Boolean]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 224
    def valid?
      valid_for_subject?(loaded_value)
    end

value() click to toggle source

Value to be compared with the subject

This value is compared against that contained in the subject when filtering collections, or the value in the repository when performing queries.

In the case of primitive property, this is the value as it is stored in the repository.

@return [Object]

@api semipublic

    # File lib/dm-core/query/conditions/comparison.rb, line 129
    def value
      dumped_value
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.