module Validatable

assumes that @checks is defined as an array of no-arg lambdas, each lambda raising an error (with useful msg) when check fails

Public Instance Methods

check_methods() click to toggle source
# File lib/musicality/validatable.rb, line 11
def check_methods; []; end
errors() click to toggle source
# File lib/musicality/validatable.rb, line 4
def errors
  if @errors.nil?
    self.validate
  end
  return @errors
end
invalid?() click to toggle source
# File lib/musicality/validatable.rb, line 40
def invalid?
  !self.valid?
end
valid?() click to toggle source
# File lib/musicality/validatable.rb, line 35
def valid?
  self.validate
  @errors.empty?
end
validatables() click to toggle source
# File lib/musicality/validatable.rb, line 12
def validatables; []; end
validate() click to toggle source
# File lib/musicality/validatable.rb, line 14
def validate
  @errors = []
  
  
  check_methods.each do |check_method|
    begin
      send(check_method)
    rescue StandardError => e
      @errors.push e
    end
  end
  
  validatables.each do |v|
    if v.respond_to?(:validate)
      @errors += v.validate
    end
  end
  
  return @errors
end