Class: Bluepine::Attributes::BooleanAttribute

Inherits:
Attribute
  • Object
show all
Defined in:
lib/bluepine/attributes/boolean_attribute.rb

Overview

Examples:

Registers custom normalizer that accepts “on” as truth value

BooleanAttribute.normalizer = ->(x) { ["on", true].include?(x) ? true : false }

Registers custom serializer

BooleanAttribute.serialize = ->(x) { x == "on" ? true : false }

Constant Summary

Constants included from Bluepine::Assertions

Bluepine::Assertions::Error, Bluepine::Assertions::KeyError, Bluepine::Assertions::SubsetError

Instance Attribute Summary

Attributes inherited from Attribute

#name

Instance Method Summary collapse

Methods inherited from Attribute

#attributes, #default, #deprecated, #description, #format, #if, #initialize, #match, #method, #null, #of, #options, #private, #required, #serializable?, #spec, #spec_uri, #type, #unless, #value

Methods included from Validators::Validatable

#validators

Methods included from Validators::Normalizable

#normalize

Methods included from Serializers::Serializable

#serialize

Methods included from Bluepine::Assertions

#assert, #assert_in, #assert_kind_of, #assert_not, #assert_subset_of, included

Constructor Details

This class inherits a constructor from Bluepine::Attributes::Attribute

Instance Method Details

#inObject



17
18
19
# File 'lib/bluepine/attributes/boolean_attribute.rb', line 17

def in
  @options.fetch(:in, [true, false])
end

#native_typeObject



13
14
15
# File 'lib/bluepine/attributes/boolean_attribute.rb', line 13

def native_type
  "boolean"
end