Module: SchemaValidations::ActiveRecord::Base::ClassMethods

Defined in:
lib/schema_validations/active_record/validations.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



13
14
15
16
17
# File 'lib/schema_validations/active_record/validations.rb', line 13

def self.extended(base)
  base.class_eval do
    class_attribute :schema_validations_loaded
  end
end

Instance Method Details

#inherited(subclass) ⇒ Object

:nodoc:



19
20
21
22
# File 'lib/schema_validations/active_record/validations.rb', line 19

def inherited(subclass) # :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


56
57
58
# File 'lib/schema_validations/active_record/validations.rb', line 56

def schema_validations(opts={})
  @schema_validations_config = SchemaValidations.config.merge({:auto_create => true}.merge(opts))
end

#schema_validations_configObject

:nodoc:



60
61
62
# File 'lib/schema_validations/active_record/validations.rb', line 60

def schema_validations_config # :nodoc:
  @schema_validations_config ||= SchemaValidations.config.dup
end

#validatorsObject



24
25
26
27
# File 'lib/schema_validations/active_record/validations.rb', line 24

def validators
  load_schema_validations unless schema_validations_loaded?
  super
end

#validators_on(*args) ⇒ Object



29
30
31
32
# File 'lib/schema_validations/active_record/validations.rb', line 29

def validators_on(*args)
  load_schema_validations unless schema_validations_loaded?
  super
end