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

Attributes

errors[R]

Public Instance Methods

check_methods() click to toggle source
# File lib/music-transcription/validatable.rb, line 6
def check_methods; []; end
invalid?() click to toggle source
# File lib/music-transcription/validatable.rb, line 35
def invalid?
  !self.valid?
end
valid?() click to toggle source
# File lib/music-transcription/validatable.rb, line 30
def valid?
  self.validate
  @errors.empty?
end
validatables() click to toggle source
# File lib/music-transcription/validatable.rb, line 7
def validatables; []; end
validate() click to toggle source
# File lib/music-transcription/validatable.rb, line 9
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