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, #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, #primitive?, #result, #success, #try

Methods included from Builder

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

Methods included from Options

#initialize, #meta, #with

Constructor Details

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

Instance Method Details

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

Parameters:

Returns:

  • (Object)

See Also:



164
165
166
167
168
169
170
# File 'lib/dry/types/hash/schema.rb', line 164

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