Class: Bioinform::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/bioinform/validator.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Validator

Returns a new instance of Validator.



56
57
58
59
60
61
62
# File 'lib/bioinform/validator.rb', line 56

def initialize(&block)
  if block_given?
    @validation_block = block
  else
    @validation_block = ->(*args, &b){ ValidationResult.new }
  end
end

Instance Method Details

#*(other) ⇒ Object

Validate both



72
73
74
75
76
# File 'lib/bioinform/validator.rb', line 72

def *(other)
  Validator.new{|*args, &b|
    validate_params(*args, &b) + other.validate_params(*args, &b)
  }
end

#make_strictObject

treat warnings as errors



79
80
81
82
83
84
# File 'lib/bioinform/validator.rb', line 79

def make_strict
  Validator.new{|*args, &block|
    result = self.validate_params(*args, &block)
    ValidationResult.new(errors: result.errors + result.warnings)
  }
end

#validate_params(*args, &block) ⇒ Object



64
65
66
67
68
69
# File 'lib/bioinform/validator.rb', line 64

def validate_params(*args, &block)
  @validation_block.call(*args, &block)
rescue => e
  msg = "Unexpected error occured during validation: #{e.message}. Backtrace:\n" + e.backtrace.join("\n")
  ValidationResult.new(errors: [msg])
end