Class: Dry::Schema::Key::Hash Private
- Inherits:
-
Dry::Schema::Key
- Object
- Dry::Schema::Key
- Dry::Schema::Key::Hash
- 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
Instance Attribute Summary collapse
- #members ⇒ Object readonly private
Attributes inherited from Dry::Schema::Key
Instance Method Summary collapse
- #coercible(&coercer) ⇒ Object private
- #dump ⇒ Object private
-
#initialize(id, members:, **opts) ⇒ Hash
constructor
private
A new instance of Hash.
- #read(source) ⇒ Object private
- #stringified ⇒ Object private
- #write(source, target) ⇒ Object private
Methods inherited from Dry::Schema::Key
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.
95 96 97 98 |
# File 'lib/dry/schema/key.rb', line 95 def initialize(id, members:, **opts) super(id, **opts) @members = members end |
Instance Attribute Details
#members ⇒ Object (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.
92 93 94 |
# File 'lib/dry/schema/key.rb', line 92 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.
112 113 114 |
# File 'lib/dry/schema/key.rb', line 112 def coercible(&coercer) new(coercer: coercer, members: members.coercible(&coercer)) end |
#dump ⇒ 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.
122 123 124 |
# File 'lib/dry/schema/key.rb', line 122 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.
101 102 103 |
# File 'lib/dry/schema/key.rb', line 101 def read(source) super if source.is_a?(::Hash) end |
#stringified ⇒ 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 stringified new(name: name.to_s, members: members.stringified) 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.
105 106 107 108 109 |
# File 'lib/dry/schema/key.rb', line 105 def write(source, target) read(source) { |value| target[coerced_name] = value.is_a?(::Hash) ? members.write(value) : value } end |