Sha256: 9f7044547346d85a13526420b71974adb14eee5f7ee177112cbf5ad08f80a7ea
Contents?: true
Size: 891 Bytes
Versions: 15
Compression:
Stored size: 891 Bytes
Contents
module Radiosonde::DSL::Validator 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 def _call_once(method_name) @called ||= [] if @called.include?(method_name) raise _identify("`#{method_name}` is already defined") end @called << method_name end def _expected_type(value, *types) unless types.any? {|t| value.kind_of?(t) } raise _identify("Invalid type: #{value}") end end def _validate(errmsg) raise _identify(errmsg) unless yield end def _identify(errmsg) if @error_identifier errmsg = "#{@error_identifier}: #{errmsg}" end return errmsg end end
Version data entries
15 entries across 15 versions & 1 rubygems