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)
-
- (Object) auto_create
:attr_accessor: auto_create.
-
- (Object) dup
:nodoc:.
-
- (Object) except
:attr_accessor: except.
-
- (Object) except_type
:attr_accessor: only_type.
-
- (Object) merge(opts)
:nodoc:.
-
- (Object) only
:attr_accessor: only.
-
- (Object) only_type
:attr_accessor: only_type.
-
- (Object) update_attributes(opts)
:nodoc:.
Instance Method Details
- (Object) auto_create
: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 |
- (Object) dup
:nodoc:
61 62 63 |
# File 'lib/schema_validations.rb', line 61 def dup #:nodoc: self.class.new(Hash[attributes.collect{ |key, val| [key, Valuable === val ? val.class.new(val.attributes) : val] }]) end |
- (Object) except
:attr_accessor: except
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 :except, :default => [:created_at, :updated_at, :created_on, :updated_on] |
- (Object) except_type
:attr_accessor: only_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.
51 |
# File 'lib/schema_validations.rb', line 51 has_value :except_type, :default => nil |
- (Object) merge(opts)
:nodoc:
72 73 74 |
# File 'lib/schema_validations.rb', line 72 def merge(opts)#:nodoc: dup.update_attributes(opts) end |
- (Object) only
: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 |
- (Object) only_type
: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.
59 |
# File 'lib/schema_validations.rb', line 59 has_value :only_type, :default => nil |
- (Object) update_attributes(opts)
:nodoc:
65 66 67 68 69 70 |
# File 'lib/schema_validations.rb', line 65 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 |