Sha256: a415a86ef4f57e679b28b3e0976ae71d09362d35c58d58d1cf083c0d9a980a9c
Contents?: true
Size: 642 Bytes
Versions: 1
Compression:
Stored size: 642 Bytes
Contents
module RC module Numericality OPERATORS = { :greater_than => :>, :greater_than_or_equal_to => :>=, :equal_to => :==, :less_than => :<, :less_than_or_equal_to => :<= }.freeze def add_numericality_constraint(table, attribute, options = {}) name = "#{table}_#{attribute}" conditions = OPERATORS.slice(*options.keys).map do |key, operator| value = options[key] [attribute, operator, value].join(" ") end.join(" AND ") execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rein-0.3.0 | lib/rein/constraint/numericality.rb |