Module: KeyVortex::Constraint
- Defined in:
- lib/key_vortex/constraint.rb,
lib/key_vortex/constraint/base.rb,
lib/key_vortex/constraint/length.rb,
lib/key_vortex/constraint/regexp.rb,
lib/key_vortex/constraint/maximum.rb,
lib/key_vortex/constraint/minimum.rb
Overview
Constraints define a restriction on the values which can be used for Record and Adapter. Although they are somewhat varied, they do have some common properties.
All constraints have some sort of attribute name and limit. In most situations, instead of the constructor, this pair will be used to specify the constraint. For example, you would typically specify a length like this:
length: 10
All constraints will inherit from Base. Because of the common ancestor, along with the need to have a single file loading all constraints, Constraint is a module instead of the base class to avoid a circular dependency.
All constraints can determine if a value is valid for them.
Most constraints, when compared with other instances of themselves, can be determined if ones limitations fit within the others. More formally, given an instance x of a constraint, an instance y of the same constraint fits within x if and only if for all values v that are valid for y, v is also valid for x.
Defined Under Namespace
Classes: Base, Length, Maximum, Minimum, Regexp
Class Method Summary collapse
-
.build(attribute, limit) ⇒ KeyVortex::Constraint::Base
Factory enabling the specification of constraints by attribute names instead of constructors.
Class Method Details
.build(attribute, limit) ⇒ KeyVortex::Constraint::Base
Factory enabling the specification of constraints by attribute names instead of constructors.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/key_vortex/constraint.rb', line 41 def self.build(attribute, limit) case attribute when :length KeyVortex::Constraint::Length.new(limit) when :maximum KeyVortex::Constraint::Maximum.new(limit) when :minimum KeyVortex::Constraint::Minimum.new(limit) when :regexp KeyVortex::Constraint::Regexp.new(limit) else raise KeyVortex::Error, "Unexpected attribute: #{attribute}" end end |