Class: SchemaValidations::Config
- Inherits:
-
Valuable
- Object
- Valuable
- SchemaValidations::Config
- Defined in:
- lib/schema_validations.rb
Overview
The configuation options for SchemaValidations. Set them globally in config/initializers/schema_validations.rb
, e.g.:
SchemaValidations.setup do |config|
config.auto_create = false
end
or override them per-model, e.g.:
class MyModel < ActiveRecord::Base
schema_validations :only => [:name, :active]
end
Instance Method Summary collapse
-
#auto_create ⇒ Object
:attr_accessor: auto_create.
-
#dup ⇒ Object
:nodoc:.
-
#except ⇒ Object
:attr_accessor: except.
-
#except_type ⇒ Object
:attr_accessor: except_type.
-
#merge(opts) ⇒ Object
:nodoc:.
-
#only ⇒ Object
:attr_accessor: only.
-
#only_type ⇒ Object
:attr_accessor: only_type.
-
#update_attributes(opts) ⇒ Object
:nodoc:.
-
#whitelist ⇒ Object
:attr_accessor: whitelist.
-
#whitelist_type ⇒ Object
:attr_accessor: whitelist_type.
Instance Method Details
#auto_create ⇒ Object
:attr_accessor: auto_create
Whether to automatically create validations based on database constraints. Boolean, default is true
.
29 |
# File 'lib/schema_validations.rb', line 29 has_value :auto_create, :klass => :boolean, :default => true |
#dup ⇒ Object
:nodoc:
76 77 78 |
# File 'lib/schema_validations.rb', line 76 def dup #:nodoc: self.class.new(Hash[attributes.collect{ |key, val| [key, Valuable === val ? val.class.new(val.attributes) : val] }]) end |
#except ⇒ Object
:attr_accessor: except
List of field names to exclude from automatic validation. Value is a single name, and array of names, or nil
. Default is nil
.
50 |
# File 'lib/schema_validations.rb', line 50 has_value :except, :default => nil |
#except_type ⇒ Object
:attr_accessor: except_type
List of validation types to exclude from automatic validation. Value is a single type, and array of types, or nil
. Default is nil
. A type is specified as, e.g., :validates_presence_of
or simply :presence
.
66 |
# File 'lib/schema_validations.rb', line 66 has_value :except_type, :default => nil |
#merge(opts) ⇒ Object
:nodoc:
87 88 89 |
# File 'lib/schema_validations.rb', line 87 def merge(opts)#:nodoc: dup.update_attributes(opts) end |
#only ⇒ Object
:attr_accessor: only
List of field names to include in automatic validation. Value is a single name, and array of names, or nil
. Default is nil
.
36 |
# File 'lib/schema_validations.rb', line 36 has_value :only, :default => nil |
#only_type ⇒ Object
:attr_accessor: only_type
List of validation types to include in automatic validation. Value is a single type, and array of types, or nil
. Default is nil
. A type is specified as, e.g., :validates_presence_of
or simply :presence
.
74 |
# File 'lib/schema_validations.rb', line 74 has_value :only_type, :default => nil |
#update_attributes(opts) ⇒ Object
:nodoc:
80 81 82 83 84 85 |
# File 'lib/schema_validations.rb', line 80 def update_attributes(opts)#:nodoc: opts = opts.dup opts.keys.each { |key| self.send(key).update_attributes(opts.delete(key)) if self.class.attributes.include? key and Hash === opts[key] } super(opts) self end |
#whitelist ⇒ Object
:attr_accessor: whitelist
List of field names to exclude from automatic validation. Value is a single name, an array of names, or nil
. Default is [:created_at, :updated_at, :created_on, :updated_on]
.
43 |
# File 'lib/schema_validations.rb', line 43 has_value :whitelist, :default => [:created_at, :updated_at, :created_on, :updated_on] |
#whitelist_type ⇒ Object
:attr_accessor: whitelist_type
List of validation types to exclude from automatic validation. Value is a single type, and array of types, or nil
. Default is nil
. A type is specified as, e.g., :validates_presence_of
or simply :presence
.
58 |
# File 'lib/schema_validations.rb', line 58 has_value :whitelist_type, :default => nil |