Module: SchemaValidations::ActiveRecord::Validations
- Defined in:
- lib/schema_validations/active_record/validations.rb
Class Method Summary collapse
-
.extended(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#inherited(klass) ⇒ Object
:nodoc:.
-
#schema_validations(opts = {}) ⇒ Object
Per-model override of Config options.
-
#schema_validations_config ⇒ Object
:nodoc:.
- #validators_on_with_schema_validations(*args) ⇒ Object
- #validators_with_schema_validations ⇒ Object
Class Method Details
.extended(base) ⇒ Object
:nodoc:
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/schema_validations/active_record/validations.rb', line 5 def self.extended(base) # :nodoc: base.class_eval do define_method :load_schema_validations do self.class.send :load_schema_validations end class_attribute :schema_validations_loaded end class << base alias_method_chain :validators, :schema_validations alias_method_chain :validators_on, :schema_validations end if base.respond_to? :validators end |
Instance Method Details
#inherited(klass) ⇒ Object
:nodoc:
18 19 20 21 |
# File 'lib/schema_validations/active_record/validations.rb', line 18 def inherited(klass) # :nodoc: super before_validation :load_schema_validations unless schema_validations_loaded? end |
#schema_validations(opts = {}) ⇒ Object
Per-model override of Config options. Use via, e.g. class MyModel < ActiveRecord::Base schema_validations :auto_create => false end
If :auto_create is not specified, it is implicitly specified as true. This allows the "non-invasive" style of using SchemaValidations in which you set the global Config to auto_create = false, then in any model that you want auto validations you simply do:
class MyModel < ActiveRecord::Base
schema_validations
end
Of course other options can be passed, such as
class MyModel < ActiveRecord::Base
schema_validations :except_type => :validates_presence_of
end
55 56 57 |
# File 'lib/schema_validations/active_record/validations.rb', line 55 def schema_validations(opts={}) @schema_validations_config = SchemaValidations.config.merge({:auto_create => true}.merge(opts)) end |
#schema_validations_config ⇒ Object
:nodoc:
59 60 61 |
# File 'lib/schema_validations/active_record/validations.rb', line 59 def schema_validations_config # :nodoc: @schema_validations_config ||= SchemaValidations.config.dup end |
#validators_on_with_schema_validations(*args) ⇒ Object
28 29 30 31 |
# File 'lib/schema_validations/active_record/validations.rb', line 28 def validators_on_with_schema_validations(*args) load_schema_validations unless schema_validations_loaded? validators_on_without_schema_validations(*args) end |
#validators_with_schema_validations ⇒ Object
23 24 25 26 |
# File 'lib/schema_validations/active_record/validations.rb', line 23 def validators_with_schema_validations load_schema_validations unless schema_validations_loaded? validators_without_schema_validations end |