Class: RSchema::Coercers::FixedHash::DefaultArraysToEmpty
- Inherits:
-
Object
- Object
- RSchema::Coercers::FixedHash::DefaultArraysToEmpty
- Defined in:
- lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb
Overview
The HTTP standard says that when a form is submitted, all unchecked check boxes will not be sent to the server. That is, they will not be present at all in the params hash.
This class coerces these missing values into an empty array, where an array is expected.
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) ⇒ DefaultArraysToEmpty
constructor
A new instance of DefaultArraysToEmpty.
- #will_affect?(value) ⇒ Boolean
Constructor Details
#initialize(fixed_hash_schema) ⇒ DefaultArraysToEmpty
Returns a new instance of DefaultArraysToEmpty.
21 22 23 24 |
# File 'lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb', line 21 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.
15 16 17 |
# File 'lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb', line 15 def hash_attributes @hash_attributes end |
Class Method Details
.build(schema) ⇒ Object
17 18 19 |
# File 'lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb', line 17 def self.build(schema) new(schema) end |
Instance Method Details
#call(value) ⇒ Object
26 27 28 |
# File 'lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb', line 26 def call(value) Result.success(default_arrays_to_empty(value)) end |
#will_affect?(value) ⇒ Boolean
30 31 32 |
# File 'lib/rschema/coercers/fixed_hash/default_arrays_to_empty.rb', line 30 def will_affect?(value) keys_to_default(value).any? end |