Module: Congo::Validation

Included in:
ContentType
Defined in:
lib/congo/validation.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(model) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/congo/validation.rb', line 4

def self.included(model)
  model.class_eval do
    include InstanceMethods
    
    validates_format_of :name, 
      :with => /^[a-zA-Z][\w\s]*$/, 
      :message => lambda { I18n.t('congo.errors.messages.invalid') }

    validates_presence_of :name, :scope, 
      :message => lambda { I18n.t('congo.errors.messages.empty') }

    validates_true_for :name,
      :logic => :check_uniqueness_of_name,
      :message => lambda { I18n.t('congo.errors.messages.taken') }

    validates_true_for :name,
      :key => :allowed_name,
      :logic => :check_allowed_name,
      :message => lambda { I18n.t('congo.errors.messages.exclusion') }

    validates_true_for :metadata_keys, 
      :logic => :validate_metadata_keys, 
      :message => lambda { I18n.t('congo.errors.messages.invalid') }

    validates_true_for :collection_name, 
      :logic => lambda { name.present? }, 
      :message => lambda { I18n.t('congo.errors.messages.empty') }

    validates_true_for :collection_name,
      :key => :unique_collection_name,
      :logic => :check_uniqueness_of_collection_name,
      :message => lambda { I18n.t('congo.errors.messages.taken') }

    validates_true_for :collection_name,
      :key => :allowed_allowed_name,
      :logic => :check_allowed_name,
      :message => lambda { I18n.t('congo.errors.messages.exclusion') }
  end
end