Module: Vhost::SiteScopedModelExtensions::InstanceMethods

Defined in:
lib/vhost/site_scoped_model_extensions.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vhost/site_scoped_model_extensions.rb', line 4

def self.included(base)
  base.class_eval {
    self.clear_callbacks_by_calling_method_name(:validate, :validates_uniqueness_of)
    validates_presence_of :site_id
    belongs_to :site

    # Parse the model_uniqueness_validations config and set any necessary validations
    # If the current class name matches an entry in the config then process it
    config = VhostExtension.MODEL_UNIQUENESS_VALIDATIONS[self.name]
    unless config.nil?
      config.each_pair do |attr, params|
        unless attr == 'sti_classes'
          validates_uniqueness_of attr.to_sym, params.symbolize_keys
        end
      end
    end
  }
end