Module: Sequel::Plugins::PgAutoConstraintValidations::ClassMethods

Defined in:
lib/sequel/plugins/pg_auto_constraint_validations.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pg_auto_constraint_validationsObject (readonly)

Hash of metadata checked when an instance attempts to convert a constraint violation into a validation failure.



124
125
126
# File 'lib/sequel/plugins/pg_auto_constraint_validations.rb', line 124

def pg_auto_constraint_validations
  @pg_auto_constraint_validations
end

#pg_auto_constraint_validations_messagesObject (readonly)

Hash of error messages keyed by constraint type symbol to use in the generated validation failures.



128
129
130
# File 'lib/sequel/plugins/pg_auto_constraint_validations.rb', line 128

def pg_auto_constraint_validations_messages
  @pg_auto_constraint_validations_messages
end

Instance Method Details

#dump_pg_auto_constraint_validations_cacheObject

Dump the in-memory cached metadata to the cache file.

Raises:



134
135
136
137
138
139
140
141
142
# File 'lib/sequel/plugins/pg_auto_constraint_validations.rb', line 134

def dump_pg_auto_constraint_validations_cache
  raise Error, "No pg_auto_constraint_validations setup" unless file = @pg_auto_constraint_validations_cache_file
  pg_auto_constraint_validations_cache = {}
  @pg_auto_constraint_validations_cache.sort.each do |k, v|
    pg_auto_constraint_validations_cache[k] = v
  end
  File.open(file, 'wb'){|f| f.write(Marshal.dump(pg_auto_constraint_validations_cache))}
  nil
end

#pg_auto_constraint_validation_override(constraint, columns, message) ⇒ Object

Override the constraint validation columns and message for a given constraint



145
146
147
148
149
150
151
152
# File 'lib/sequel/plugins/pg_auto_constraint_validations.rb', line 145

def pg_auto_constraint_validation_override(constraint, columns, message)
  pgacv = Hash[@pg_auto_constraint_validations]
  overrides = pgacv[:overrides] = Hash[pgacv[:overrides]]
  overrides[constraint] = [Array(columns), message].freeze
  overrides.freeze
  @pg_auto_constraint_validations = pgacv.freeze
  nil
end