Sha256: 3518d54cd523c4d64d5ffb2ba75966d0ca1ca970e30f2bc070f7d5d0ca35f86c
Contents?: true
Size: 643 Bytes
Versions: 8
Compression:
Stored size: 643 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
8 entries across 8 versions & 1 rubygems