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
.
30 |
# File 'lib/schema_validations.rb', line 30 has_value :auto_create, :klass => :boolean, :default => true |
#dup ⇒ Object
:nodoc:
77 78 79 |
# File 'lib/schema_validations.rb', line 77 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
.
51 |
# File 'lib/schema_validations.rb', line 51 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
.
67 |
# File 'lib/schema_validations.rb', line 67 has_value :except_type, :default => nil |
#merge(opts) ⇒ Object
:nodoc:
88 89 90 |
# File 'lib/schema_validations.rb', line 88 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
.
37 |
# File 'lib/schema_validations.rb', line 37 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
.
75 |
# File 'lib/schema_validations.rb', line 75 has_value :only_type, :default => nil |
#update_attributes(opts) ⇒ Object
:nodoc:
81 82 83 84 85 86 |
# File 'lib/schema_validations.rb', line 81 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]
.
44 |
# File 'lib/schema_validations.rb', line 44 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
.
59 |
# File 'lib/schema_validations.rb', line 59 has_value :whitelist_type, :default => nil |