Class: RSchema::Coercers::FixedHash::SymbolizeKeys
- Inherits:
-
Object
- Object
- RSchema::Coercers::FixedHash::SymbolizeKeys
- Defined in:
- lib/rschema/coercers/fixed_hash/symbolize_keys.rb
Overview
Coerces ‘String` keys into `Symbol`s according to the attributes in a given `FixedHash` schema.
Instance Attribute Summary collapse
-
#hash_attributes ⇒ Object
readonly
Returns the value of attribute hash_attributes.
Class Method Summary collapse
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(fixed_hash_schema) ⇒ SymbolizeKeys
constructor
A new instance of SymbolizeKeys.
- #will_affect?(_value) ⇒ Boolean
Constructor Details
#initialize(fixed_hash_schema) ⇒ SymbolizeKeys
19 20 21 22 |
# File 'lib/rschema/coercers/fixed_hash/symbolize_keys.rb', line 19 def initialize(fixed_hash_schema) # TODO: make fixed hash attributes frozen, and eliminate dup @hash_attributes = fixed_hash_schema.attributes.map(&:dup) end |
Instance Attribute Details
#hash_attributes ⇒ Object (readonly)
Returns the value of attribute hash_attributes.
13 14 15 |
# File 'lib/rschema/coercers/fixed_hash/symbolize_keys.rb', line 13 def hash_attributes @hash_attributes end |
Class Method Details
.build(schema) ⇒ Object
15 16 17 |
# File 'lib/rschema/coercers/fixed_hash/symbolize_keys.rb', line 15 def self.build(schema) new(schema) end |
Instance Method Details
#call(value) ⇒ Object
24 25 26 |
# File 'lib/rschema/coercers/fixed_hash/symbolize_keys.rb', line 24 def call(value) Result.success(symbolize_keys(value)) end |
#will_affect?(_value) ⇒ Boolean
28 29 30 |
# File 'lib/rschema/coercers/fixed_hash/symbolize_keys.rb', line 28 def will_affect?(_value) keys_to_symbolize(hash).any? end |