Class: Dry::Schema::Key::Hash Private

Inherits:
Dry::Schema::Key show all
Defined in:
lib/dry/schema/key.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A specialized key type which handles nested hashes

Constant Summary

Constants inherited from Dry::Schema::Key

DEFAULT_COERCER

Instance Attribute Summary collapse

Attributes inherited from Dry::Schema::Key

#coercer, #id, #name

Instance Method Summary collapse

Methods inherited from Dry::Schema::Key

[], new, #new

Constructor Details

#initialize(id, members:, **opts) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Hash.



100
101
102
103
# File 'lib/dry/schema/key.rb', line 100

def initialize(id, members:, **opts)
  super(id, **opts)
  @members = members
end

Instance Attribute Details

#membersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



97
98
99
# File 'lib/dry/schema/key.rb', line 97

def members
  @members
end

Instance Method Details

#coercible(&coercer) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



117
118
119
# File 'lib/dry/schema/key.rb', line 117

def coercible(&coercer)
  new(coercer: coercer, members: members.coercible(&coercer))
end

#dumpObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/dry/schema/key.rb', line 132

def dump
  {name => members.map(&:dump)}
end

#read(source) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



106
107
108
# File 'lib/dry/schema/key.rb', line 106

def read(source)
  super if source.is_a?(::Hash)
end

#stringifiedObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



122
123
124
# File 'lib/dry/schema/key.rb', line 122

def stringified
  new(name: name.to_s, members: members.stringified)
end

#to_dot_notationObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



127
128
129
# File 'lib/dry/schema/key.rb', line 127

def to_dot_notation
  [name].product(members.flat_map(&:to_dot_notation)).map { |e| e.join(DOT) }
end

#write(source, target) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



110
111
112
113
114
# File 'lib/dry/schema/key.rb', line 110

def write(source, target)
  read(source) { |value|
    target[coerced_name] = value.is_a?(::Hash) ? members.write(value) : value
  }
end