Module: ActiveFolder::Model::Traits::Validation

Included in:
Base
Defined in:
lib/activefolder/model/traits/validation.rb

Instance Method Summary collapse

Instance Method Details

#validate(attribute, schema, message = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/activefolder/model/traits/validation.rb', line 9

def validate attribute, schema, message = nil
  before_save do
    unless schema.match(self.send attribute)
      raise ValidationError.new(attribute, schema, message)
    end
  end

  after_load do
    unless schema.match(self.send attribute)
      raise ValidationError.new(attribute, schema, message)
    end
  end
end