Class: ActiveModel::Type::Binary

Inherits:
Value show all
Defined in:
activemodel/lib/active_model/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

#==, #assert_valid_value, #changed?, #deserialize, #hash, #initialize, #map, #type_cast_for_schema

Constructor Details

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

Instance Method Details

#binary?Boolean


8
9
10
# File 'activemodel/lib/active_model/type/binary.rb', line 8

def binary?
  true
end

#cast(value) ⇒ Object


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

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

#changed_in_place?(raw_old_value, value) ⇒ Boolean


25
26
27
28
# File 'activemodel/lib/active_model/type/binary.rb', line 25

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

#serialize(value) ⇒ Object


20
21
22
23
# File 'activemodel/lib/active_model/type/binary.rb', line 20

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

#typeObject


4
5
6
# File 'activemodel/lib/active_model/type/binary.rb', line 4

def type
  :binary
end