Method: Sequel::Plugins::PgAutoConstraintValidations.configure
- Defined in:
- lib/sequel/plugins/pg_auto_constraint_validations.rb
.configure(model, opts = OPTS) ⇒ Object
Setup the constraint violation metadata. Options:
- :cache_file
-
File storing cached metadata, to avoid queries for each model
- :messages
-
Override the default error messages for each constraint violation type (:not_null, :check, :unique, :foreign_key, :referenced_by)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sequel/plugins/pg_auto_constraint_validations.rb', line 100 def self.configure(model, opts=OPTS) model.instance_exec do if @pg_auto_constraint_validations_cache_file = opts[:cache_file] @pg_auto_constraint_validations_cache = if ::File.file?(@pg_auto_constraint_validations_cache_file) cache = Marshal.load(File.read(@pg_auto_constraint_validations_cache_file)) cache.each_value do |hash| hash.freeze.each_value(&:freeze) end else {} end else @pg_auto_constraint_validations_cache = nil end setup_pg_auto_constraint_validations = ( || DEFAULT_ERROR_MESSAGES).merge(opts[:messages] || OPTS).freeze end nil end |