Module: Mead::Validations

Included in:
Identifier
Defined in:
lib/mead/validations.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/mead/validations.rb', line 3

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#errorsObject



32
33
34
# File 'lib/mead/validations.rb', line 32

def errors
  @errors ||= {}
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/mead/validations.rb', line 21

def valid?
  validate_format
  validate
  errors.nil? or errors.empty?
end

#valid_format?Boolean

Returns:

  • (Boolean)


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

def valid_format?
  validate_format
  errors.nil? or errors.empty?
end

#validateObject



7
8
9
10
11
12
# File 'lib/mead/validations.rb', line 7

def validate
  errors.clear
  self.class.validations.each do |validation|
    validation.call(self)
  end
end

#validate_formatObject



14
15
16
17
18
19
# File 'lib/mead/validations.rb', line 14

def validate_format
  errors.clear
  self.class.format_validations.each do |validation|
    validation.call(self)
  end
end