module Kind::STRICT
Public Instance Methods
assert_hash!(hash, options)
click to toggle source
# File lib/kind/__lib__/strict.rb, line 55 def assert_hash!(hash, options) require_all = options[:require_all] return assert_hash_keys!(hash, options[:keys], require_all) if options.key?(:keys) return assert_hash_schema!(hash, options[:schema], require_all) if options.key?(:schema) raise ArgumentError, ':keys or :schema is missing' end
in!(list, value)
click to toggle source
# File lib/kind/__lib__/strict.rb, line 49 def in!(list, value) return value if list.include?(value) raise Error.new("#{value} expected to be included in #{list.inspect}") end
Private Instance Methods
assert_hash_keys!(hash, arg, require_all)
click to toggle source
# File lib/kind/__lib__/strict.rb, line 66 def assert_hash_keys!(hash, arg, require_all) keys = Array(arg) ASSERT_HASH_KEYS.require_all(keys, hash) if require_all hash.each_key do |k| unless keys.include?(k) raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{keys.map(&:inspect).join(', ')}") end end end
assert_hash_schema!(hash, schema, require_all)
click to toggle source
# File lib/kind/__lib__/strict.rb, line 78 def assert_hash_schema!(hash, schema, require_all) return ASSERT_HASH_SCHEMA.all(hash, schema) if require_all ASSERT_HASH_SCHEMA.any(hash, schema) end