Sha256: c647b0419b85d0ff5067dfee1c0710f999172d000ff2fecee3ff6a8cf4780460
Contents?: true
Size: 791 Bytes
Versions: 21
Compression:
Stored size: 791 Bytes
Contents
module FunWithJsonApi module Attributes # Ensures a value is either Boolean.TRUE, Boolean.FALSE or nil # Raises an argument error otherwise class BooleanAttribute < Attribute def call(value) return nil if value.nil? return value if value.is_a?(TrueClass) || value.is_a?(FalseClass) raise build_invalid_attribute_error(value) end private def build_invalid_attribute_error(value) exception_message = I18n.t('fun_with_json_api.exceptions.invalid_boolean_attribute') payload = ExceptionPayload.new payload.detail = exception_message payload.pointer = "/data/attributes/#{name}" Exceptions::InvalidAttribute.new(exception_message + ": #{value.inspect}", payload) end end end end
Version data entries
21 entries across 21 versions & 1 rubygems