module Radiosonde::DSL::Validator

Public Instance Methods

_call_once(method_name) click to toggle source
# File lib/radiosonde/dsl/validator.rb, line 19
def _call_once(method_name)
  @called ||= []

  if @called.include?(method_name)
    raise _identify("`#{method_name}` is already defined")
  end

  @called << method_name
end
_expected_type(value, *types) click to toggle source
# File lib/radiosonde/dsl/validator.rb, line 29
def _expected_type(value, *types)
  unless types.any? {|t| value.kind_of?(t) }
    raise _identify("Invalid type: #{value}")
  end
end
_identify(errmsg) click to toggle source
# File lib/radiosonde/dsl/validator.rb, line 39
def _identify(errmsg)
  if @error_identifier
    errmsg = "#{@error_identifier}: #{errmsg}"
  end

  return errmsg
end
_required(name, value) click to toggle source
# File lib/radiosonde/dsl/validator.rb, line 2
def _required(name, value)
  invalid = false

  if value
    case value
    when String
      invalid = value.strip.empty?
    when Array, Hash
      invalid = value.empty?
    end
  elsif value.nil?
    invalid = true
  end

  raise _identify("`#{name}` is required") if invalid
end
_validate(errmsg) { || ... } click to toggle source
# File lib/radiosonde/dsl/validator.rb, line 35
def _validate(errmsg)
  raise _identify(errmsg) unless yield
end