module SchemaValidations::ActiveRecord::Base::ClassMethods
Public Class Methods
extended(base)
click to toggle source
# 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
Public Instance Methods
schema_validations(opts={})
click to toggle source
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
# 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
validators()
click to toggle source
Calls superclass method
# File lib/schema_validations/active_record/validations.rb, line 24 def validators load_schema_validations unless schema_validations_loaded? super end
validators_on(*args)
click to toggle source
Calls superclass method
# File lib/schema_validations/active_record/validations.rb, line 29 def validators_on(*args) load_schema_validations unless schema_validations_loaded? super end
Private Instance Methods
has_case_insensitive_index?(column, scope)
click to toggle source
# File lib/schema_validations/active_record/validations.rb, line 191 def has_case_insensitive_index?(column, scope) indexed_columns = (scope + [column.name]).map(&:to_sym).sort index = column.indexes.select { |i| i.unique && i.columns.map(&:to_sym).sort == indexed_columns }.first index && index.respond_to?(:case_sensitive?) && !index.case_sensitive? end