Class: RSchema::Coercers::FixedHash::DefaultBooleansToFalse
- Inherits:
-
Object
- Object
- RSchema::Coercers::FixedHash::DefaultBooleansToFalse
- Defined in:
- lib/rschema/coercers/fixed_hash/default_booleans_to_false.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 ‘false`.
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) ⇒ DefaultBooleansToFalse
constructor
A new instance of DefaultBooleansToFalse.
Constructor Details
#initialize(fixed_hash_schema) ⇒ DefaultBooleansToFalse
19 20 21 22 |
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.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/default_booleans_to_false.rb', line 13 def hash_attributes @hash_attributes end |
Class Method Details
.build(schema) ⇒ Object
15 16 17 |
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.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/default_booleans_to_false.rb', line 24 def call(value) Result.success(default_bools_to_false(value)) end |