Class: RSchema::Coercers::FixedHash::DefaultBooleansToFalse

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fixed_hash_schema) ⇒ DefaultBooleansToFalse


20
21
22
23
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb', line 20

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


14
15
16
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb', line 14

def hash_attributes
  @hash_attributes
end

Class Method Details

.build(schema) ⇒ Object


16
17
18
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb', line 16

def self.build(schema)
  new(schema)
end

Instance Method Details

#call(value) ⇒ Object


25
26
27
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb', line 25

def call(value)
  Result.success(default_bools_to_false(value))
end

#will_affect?(value) ⇒ Boolean


29
30
31
# File 'lib/rschema/coercers/fixed_hash/default_booleans_to_false.rb', line 29

def will_affect?(value)
  keys_to_default(value).any?
end