Sha256: c093d919479393b48a5d6da259ac1d1e2be7eac2b58b934428657596778fdb1c

Contents?: true

Size: 475 Bytes

Versions: 11

Compression:

Stored size: 475 Bytes

Contents

require 'active_record/connection_adapters/abstract/quoting'

module RC
  module Inclusion
    include ActiveRecord::ConnectionAdapters::Quoting

    def add_inclusion_constraint(table, attribute, options = {})
      name       = "#{table}_#{attribute}"
      values     = options[:in].map {|value| quote(value) }.join(", ")
      conditions = "#{attribute} IN (#{values})"
      execute("ALTER TABLE #{table} ADD CONSTRAINT #{name} CHECK (#{conditions})")
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rein-0.8.3 lib/rein/constraint/inclusion.rb
rein-0.8.2 lib/rein/constraint/inclusion.rb
rein-0.8.1 lib/rein/constraint/inclusion.rb
rein-0.8.0 lib/rein/constraint/inclusion.rb
rein-0.7.1 lib/rein/constraint/inclusion.rb
rein-0.7.0 lib/rein/constraint/inclusion.rb
rein-0.6.0 lib/rein/constraint/inclusion.rb
rein-0.5.2 lib/rein/constraint/inclusion.rb
rein-0.5.1 lib/rein/constraint/inclusion.rb
rein-0.5.0 lib/rein/constraint/inclusion.rb
rein-0.4.0 lib/rein/constraint/inclusion.rb