Class: ActiveRecord::ConnectionAdapters::Sunstone::Type::Binary

Inherits:
Type::Binary
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sunstone/type/binary.rb

Instance Method Summary collapse

Instance Method Details

#deserialize(value) ⇒ Object

Converts a value from database input to the appropriate ruby type. The return value of this method will be returned from ActiveRecord::AttributeMethods::Read#read_attribute. The default implementation just calls Value#cast.

value The raw input, as provided from the database.



15
16
17
# File 'lib/active_record/connection_adapters/sunstone/type/binary.rb', line 15

def deserialize(value)
  value.nil? ? nil : Base64.strict_decode64(value)            
end

#serialize(value) ⇒ Object

Casts a value from the ruby type to a type that the database knows how to understand. The returned value from this method should be a String, Numeric, Date, Time, Symbol, true, false, or nil.



23
24
25
26
27
28
# File 'lib/active_record/connection_adapters/sunstone/type/binary.rb', line 23

def serialize(value)
  if limit && value.bytesize > limit
    raise ActiveModel::RangeError, "value is out of range for #{self.class} with limit #{limit} bytes"
  end
  Base64.strict_encode64(value)
end