Class: Dry::Types::Hash::StrictWithDefaults

Inherits:
Strict show all
Includes:
MaybeTypes
Defined in:
lib/dry/types/hash/schema.rb,
lib/dry/types/extensions/maybe.rb

Overview

StrictWithDefaults checks that there are no extra keys (raises UnknownKeysError otherwise) and there a no missing keys without default values given (raises MissingKeyError otherwise).

Instance Attribute Summary

Attributes inherited from Schema

#member_types

Attributes inherited from Definition

#options, #primitive

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Strict

#resolve

Methods inherited from Schema

#call, #coerce, #initialize, #resolve, #to_ast, #try, #try_coerce

Methods inherited from Dry::Types::Hash

#permissive, #schema, #strict, #strict_with_defaults, #symbolized, #weak

Methods inherited from Definition

[], #call, #constrained?, #default?, #failure, #initialize, #name, #optional?, #primitive?, #result, #success, #to_ast, #try

Methods included from Builder

#constrained, #constrained_type, #constructor, #default, #enum, #maybe, #optional, #safe, #|

Methods included from Options

#initialize, #meta, #pristine, #with

Constructor Details

This class inherits a constructor from Dry::Types::Hash::Schema

Instance Method Details

#hash_typeObject (private)



186
187
188
# File 'lib/dry/types/hash/schema.rb', line 186

def hash_type
  :strict_with_defaults
end

#resolve_missing_value(result, key, type) ⇒ Object (private)

Parameters:

  • result (Hash)
  • key (Symbol)
  • type (Type)

Returns:

  • (Object)

See Also:



196
197
198
199
200
201
202
# File 'lib/dry/types/hash/schema.rb', line 196

def resolve_missing_value(result, key, type)
  if type.default?
    result[key] = type.evaluate
  else
    super
  end
end