Class: DataMapper::Query::Conditions::Comparison

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-core/query/conditions/comparison.rb

Overview

An abstract class which provides easy access to comparison operators

Examples:

Creating a new comparison

Comparison.new(:eql, MyClass.my_property, "value")

Class Method Summary collapse

Class Method Details

.new(slug, subject, value) ⇒ DataMapper::Query::Conditions::AbstractComparison

Creates a new Comparison instance

The returned instance will be suitable for matching the given subject (property or relationship) against the value.

Examples:

Comparison.new(:eql, MyClass.properties[:id], 1)

Parameters:

  • slug (Symbol)

    The type of comparison operator required. One of: :eql, :in, :gt, :gte, :lt, :lte, :regexp, :like.

  • The (Property, Associations::Relationship)

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

  • value (Object)

    The value for the comparison.

Returns:



58
59
60
61
62
63
64
# File 'lib/dm-core/query/conditions/comparison.rb', line 58

def self.new(slug, subject, value)
  if klass = comparison_class(slug)
    klass.new(subject, value)
  else
    raise ArgumentError, "No Comparison class for #{slug.inspect} has been defined"
  end
end

.slugsArray<Symbol>

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 an array of all slugs registered with Comparison

Returns:



71
72
73
# File 'lib/dm-core/query/conditions/comparison.rb', line 71

def self.slugs
  AbstractComparison.descendants.map { |comparison_class| comparison_class.slug }
end