class DataMapper::Query::Conditions::Operation
Public Class Methods
new(slug, *operands)
click to toggle source
Factory method to initialize an operation
@example
operation = Operation.new(:and, comparison)
@param [Symbol] slug
the identifier for the operation class
@param [Array] *operands
the operands to initialize the operation with
@return [AbstractOperation]
the operation matching the slug
@api semipublic
# File lib/dm-core/query/conditions/operation.rb, line 19 def self.new(slug, *operands) if klass = operation_class(slug) klass.new(*operands) else raise ArgumentError, "No Operation class for #{slug.inspect} has been defined" end end
slugs()
click to toggle source
Return an Array of all the slugs for the operation classes
@return [Array]
the slugs of all the operation classes
@api private
# File lib/dm-core/query/conditions/operation.rb, line 33 def self.slugs AbstractOperation.descendants.map { |operation_class| operation_class.slug } end
Private Class Methods
operation_class(slug)
click to toggle source
Lookup the operation class based on the slug
@example
operation_class = Operation.operation_class(:and)
@param [Symbol] slug
the identifier for the operation class
@return [Class]
the operation class
@api private
# File lib/dm-core/query/conditions/operation.rb, line 62 def operation_class(slug) operation_classes[slug] ||= AbstractOperation.descendants.detect { |operation_class| operation_class.slug == slug } end
operation_classes()
click to toggle source
Returns a Hash mapping the slugs to each class
@return [Hash]
Hash mapping the slug to the class
@api private
# File lib/dm-core/query/conditions/operation.rb, line 46 def operation_classes @operation_classes ||= {} end