Class: ActiveModel::Type::Binary

Inherits:
Value
  • Object
show all
Defined in:
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, #force_equality?, #hash, #immutable_value, #initialize, #map, #serializable?, #type_cast_for_schema, #value_constructed_by_mass_assignment?

Constructor Details

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

Instance Method Details

#binary?Boolean

Returns:



10
11
12
# File 'lib/active_model/type/binary.rb', line 10

def binary?
  true
end

#cast(value) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/active_model/type/binary.rb', line 14

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

#changed_in_place?(raw_old_value, value) ⇒ Boolean

Returns:



27
28
29
30
# File 'lib/active_model/type/binary.rb', line 27

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

#serialize(value) ⇒ Object



22
23
24
25
# File 'lib/active_model/type/binary.rb', line 22

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

#typeObject



6
7
8
# File 'lib/active_model/type/binary.rb', line 6

def type
  :binary
end