Class: RSchema::Coercers::FixedHash::RemoveExtraneousAttributes
- Inherits:
-
Object
- Object
- RSchema::Coercers::FixedHash::RemoveExtraneousAttributes
- Defined in:
- lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb
Overview
Removes elements from ‘Hash` values that are not defined in the 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) ⇒ RemoveExtraneousAttributes
constructor
A new instance of RemoveExtraneousAttributes.
- #will_affect?(value) ⇒ Boolean
Constructor Details
#initialize(fixed_hash_schema) ⇒ RemoveExtraneousAttributes
Returns a new instance of RemoveExtraneousAttributes.
17 18 19 20 |
# File 'lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb', line 17 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.
11 12 13 |
# File 'lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb', line 11 def hash_attributes @hash_attributes end |
Class Method Details
.build(schema) ⇒ Object
13 14 15 |
# File 'lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb', line 13 def self.build(schema) new(schema) end |
Instance Method Details
#call(value) ⇒ Object
22 23 24 |
# File 'lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb', line 22 def call(value) Result.success(remove_extraneous_elements(value)) end |
#will_affect?(value) ⇒ Boolean
26 27 28 |
# File 'lib/rschema/coercers/fixed_hash/remove_extraneous_attributes.rb', line 26 def will_affect?(value) keys_to_remove(value).any? end |