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



11
12
13
14
15
# File 'lib/schema_validations/active_record/validations.rb', line 11

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

Instance Method Details

#inherited(subclass) ⇒ Object

:nodoc:



17
18
19
20
# File 'lib/schema_validations/active_record/validations.rb', line 17

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


54
55
56
# File 'lib/schema_validations/active_record/validations.rb', line 54

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

#schema_validations_configObject

:nodoc:



58
59
60
# File 'lib/schema_validations/active_record/validations.rb', line 58

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

#validatorsObject



22
23
24
25
# File 'lib/schema_validations/active_record/validations.rb', line 22

def validators
  load_schema_validations unless schema_validations_loaded?
  super
end

#validators_on(*args) ⇒ Object



27
28
29
30
# File 'lib/schema_validations/active_record/validations.rb', line 27

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