module Spark::CommandValidator

Public Instance Methods

valid?(value, options) click to toggle source
# File lib/spark/command_validator.rb, line 8
def valid?(value, options)
  begin
    validate(value, options)
    return true
  rescue
    return false
  end
end
validate(value, options) click to toggle source
# File lib/spark/command_validator.rb, line 4
def validate(value, options)
  validate_type(value, options[:type])
end
validate_size(array1, array2) click to toggle source
# File lib/spark/command_validator.rb, line 27
def validate_size(array1, array2)
  if array1.size != array2.size
    error "Wrong number of arguments (#{array1.size} for #{array2.size})"
  end
end
validate_type(value, types) click to toggle source
# File lib/spark/command_validator.rb, line 17
def validate_type(value, types)
  types = [types] if !types.is_a?(Array)

  types.each do |type|
    return if value.is_a?(type)
  end

  error "Value: #{value} should be a #{types.join(' or ')} but is #{value.class}."
end