Sha256: 3f2854050d76f481e27ab3994c4c99c0b72b8b5caeb4295081a67266b170c497

Contents?: true

Size: 639 Bytes

Versions: 1

Compression:

Stored size: 639 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 = {})
      conditions = OPERATORS.slice(*options.keys).map do |key, operator|
        value = options[key]
        [attribute, operator, value].join(" ")
      end

      conditions = conditions.join(" AND ")

      execute "ALTER TABLE #{table} ADD CONSTRAINT #{attribute} CHECK (#{conditions})"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rein-0.2.1 lib/rein/constraint/numericality.rb