Class: Dry::Schema::KeyCoercer Private

Inherits:
Object
  • Object
show all
Extended by:
Core::Cache
Defined in:
lib/dry/schema/key_coercer.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.

Coerces keys in a hash using provided coercer function

Constant Summary collapse

TO_SYM =

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

:to_sym.to_proc.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_map, &coercer) ⇒ KeyCoercer

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 KeyCoercer.



30
31
32
# File 'lib/dry/schema/key_coercer.rb', line 30

def initialize(key_map, &coercer)
  @key_map = key_map.coercible(&coercer)
end

Instance Attribute Details

#coercerObject (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.



17
18
19
# File 'lib/dry/schema/key_coercer.rb', line 17

def coercer
  @coercer
end

#key_mapObject (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.



17
18
19
# File 'lib/dry/schema/key_coercer.rb', line 17

def key_map
  @key_map
end

Class Method Details

.new(*args) ⇒ 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.



20
21
22
# File 'lib/dry/schema/key_coercer.rb', line 20

def self.new(*args)
  fetch_or_store(*args) { super }
end

.symbolized(*args) ⇒ 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.



25
26
27
# File 'lib/dry/schema/key_coercer.rb', line 25

def self.symbolized(*args)
  new(*args, &TO_SYM)
end

Instance Method Details

#call(result) ⇒ Object Also known as: []

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.



35
36
37
# File 'lib/dry/schema/key_coercer.rb', line 35

def call(result)
  key_map.write(result.to_h)
end