Class: FunWithJsonApi::Attributes::BooleanAttribute

Inherits:
FunWithJsonApi::Attribute show all
Defined in:
lib/fun_with_json_api/attributes/boolean_attribute.rb

Overview

Ensures a value is either Boolean.TRUE, Boolean.FALSE or nil Raises an argument error otherwise

Instance Attribute Summary

Attributes inherited from FunWithJsonApi::Attribute

#as, #name, #options

Instance Method Summary collapse

Methods inherited from FunWithJsonApi::Attribute

create, #initialize, #param_value, #sanitize_attribute_method

Constructor Details

This class inherits a constructor from FunWithJsonApi::Attribute

Instance Method Details

#decode(value) ⇒ Object



6
7
8
9
10
11
# File 'lib/fun_with_json_api/attributes/boolean_attribute.rb', line 6

def decode(value)
  return nil if value.nil?
  return value if value.is_a?(TrueClass) || value.is_a?(FalseClass)

  raise build_invalid_attribute_error(value)
end