Sha256: 7a4fd5bd4dcbe5a4b68767ad5abd0ac331e41654d5a8cc981e2c58a34d3388c5
Contents?: true
Size: 673 Bytes
Versions: 1
Compression:
Stored size: 673 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 self.add_numericality_constraint(table, attribute, options) conditions = OPERATORS.slice(*options.keys).map do |key, operator| value = options[key] [attribute, operator, value].join(" ") end conditions_sql = conditions.map {|condition| "(#{condition})" }.join(" AND ") "ALTER TABLE #{table} ADD CONSTRAINT #{attribute} CHECK #{conditions_sql}" end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rein-0.1.0 | lib/rein/constraint/numericality.rb |