Class: Stannum::Constraints::Types::HashWithStringKeys

Inherits:
HashType show all
Defined in:
lib/stannum/constraints/types/hash_with_string_keys.rb

Overview

Asserts that the object is a Hash with String keys.

Constant Summary

Constants inherited from Stannum::Constraints::Type

Stannum::Constraints::Type::NEGATED_TYPE, Stannum::Constraints::Type::TYPE

Constants inherited from Base

Base::NEGATED_TYPE, Base::TYPE

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from HashType

#allow_empty?, #does_not_match?, #errors_for, #key_type, #matches?, #value_type

Methods inherited from Stannum::Constraints::Type

#errors_for, #expected_type, #matches?, #negated_errors_for, #with_options

Methods included from Support::Optional

#optional?, #required?, resolve

Methods inherited from Base

#==, #clone, #does_not_match?, #dup, #errors_for, #match, #matches?, #message, #negated_errors_for, #negated_match, #negated_message, #negated_type, #type, #with_options

Constructor Details

#initialize(value_type: nil, **options) ⇒ HashWithStringKeys

Returns a new instance of HashWithStringKeys.

Parameters:

  • value_type (Stannum::Constraints::Base, Class, nil) (defaults to: nil)

    If set, then the constraint will check the types of each value in the Hash against the expected type and will fail if any values do not match.

  • options (Hash<Symbol, Object>)

    Configuration options for the constraint. Defaults to an empty Hash.



13
14
15
16
17
18
19
# File 'lib/stannum/constraints/types/hash_with_string_keys.rb', line 13

def initialize(value_type: nil, **options)
  super(
    key_type:   Stannum::Constraints::Types::StringType.new,
    value_type: coerce_value_type(value_type),
    **options
  )
end