Class: DataTypes::Bool
- Defined in:
- lib/active_model_serializers_binary/data_types.rb
Instance Attribute Summary
Attributes inherited from BaseType
#bit_length, #count, #length, #name, #parent, #raw_value, #sign, #type, #value
Instance Method Summary collapse
- #dump(value = nil) ⇒ Object
-
#initialize(options = {}) ⇒ Bool
constructor
A new instance of Bool.
- #load(raw_value) ⇒ Object
Methods inherited from BaseType
#after_load, #before_dump, #check, #check_raw_value, #check_value, #size, #to_s, #trim
Constructor Details
#initialize(options = {}) ⇒ Bool
Returns a new instance of Bool.
157 158 159 |
# File 'lib/active_model_serializers_binary/data_types.rb', line 157 def initialize( = {}) super .merge :bit_length => 1, :default_value => false end |
Instance Method Details
#dump(value = nil) ⇒ Object
161 162 163 164 |
# File 'lib/active_model_serializers_binary/data_types.rb', line 161 def dump(value=nil) before_dump( value ) @raw_value = Array(@value.map{|v| v ? 1 : 0}.join).pack('b*').unpack('C*') end |
#load(raw_value) ⇒ Object
166 167 168 169 |
# File 'lib/active_model_serializers_binary/data_types.rb', line 166 def load(raw_value) self.value = check_raw_value(raw_value).pack('C*').unpack('b*').first.slice(0,size*8).split('').map(&:to_i) if !value.nil? after_load end |