Sha256: 42d945a1a3a3cc6fe3bdc120af4ad04aa695e3694c26b85cb1f6029658f921c8

Contents?: true

Size: 436 Bytes

Versions: 2

Compression:

Stored size: 436 Bytes

Contents

module Rein
  module Constraint
    # This module contains methods for defining presence constraints.
    module Presence
      include ActiveRecord::ConnectionAdapters::Quoting

      def add_presence_constraint(table, attribute)
        name       = "#{table}_#{attribute}"
        conditions = "#{attribute} !~ '^\s*$'"
        execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rein-1.1.0 lib/rein/constraint/presence.rb
rein-1.0.0 lib/rein/constraint/presence.rb