Class: RSchema::Coercers::FixedHash::RemoveExtraneousAttributes

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixed_hash_schema) ⇒ 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_attributesObject (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