class Ground::Validate

Attributes

errors[R]
validations[R]

Public Class Methods

new(data) click to toggle source
Calls superclass method
# File lib/ground/activity/validate.rb, line 6
def initialize(data)
  super
  @errors = {}
  @validations = []
end

Public Instance Methods

call() click to toggle source
# File lib/ground/activity/validate.rb, line 12
def call
  execute_validations
end

Private Instance Methods

execute_validations() click to toggle source
# File lib/ground/activity/validate.rb, line 25
def execute_validations
  validations.each {|validation|
    attr, error_msg, p = validation
    if !p.call
      errors[attr] ||= []
      errors[attr] << error_msg if !errors[attr].include?(error_msg)
    end
  }
  errors
end
validates(attr, error_msg, &p) click to toggle source
# File lib/ground/activity/validate.rb, line 18
def validates(attr, error_msg, &p)
  validation = validations.detect {|validation|
    validation[0] == attr and validation[1] == error_msg
  } || [attr, error_msg, p]
  validations << validation
end