Class: ActiveRecord::Type::Binary

Inherits:
Value show all
Defined in:
activerecord/lib/active_record/type/binary.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Data

Instance Attribute Summary

Attributes inherited from Value

#limit, #precision, #scale

Instance Method Summary collapse

Methods inherited from Value

#==, #changed?, #hash, #initialize, #klass, #number?, #text?, #type_cast_for_schema, #type_cast_from_database, #type_cast_from_user

Constructor Details

This class inherits a constructor from ActiveRecord::Type::Value

Instance Method Details

#binary?Boolean

Returns:


8
9
10
# File 'activerecord/lib/active_record/type/binary.rb', line 8

def binary?
  true
end

#changed_in_place?(raw_old_value, value) ⇒ Boolean

Returns:


25
26
27
28
# File 'activerecord/lib/active_record/type/binary.rb', line 25

def changed_in_place?(raw_old_value, value)
  old_value = type_cast_from_database(raw_old_value)
  old_value != value
end

#typeObject


4
5
6
# File 'activerecord/lib/active_record/type/binary.rb', line 4

def type
  :binary
end

#type_cast(value) ⇒ Object


12
13
14
15
16
17
18
# File 'activerecord/lib/active_record/type/binary.rb', line 12

def type_cast(value)
  if value.is_a?(Data)
    value.to_s
  else
    super
  end
end

#type_cast_for_database(value) ⇒ Object


20
21
22
23
# File 'activerecord/lib/active_record/type/binary.rb', line 20

def type_cast_for_database(value)
  return if value.nil?
  Data.new(super)
end