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

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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.



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

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