Skip to Content Skip to Search

Attribute type for representation of binary data. This type is registered under the :binary key.

Non-string values are coerced to strings using their to_s method.

Methods
B
C
S
T

Instance Public methods

binary?()

# File activemodel/lib/active_model/type/binary.rb, line 14
def binary?
  true
end

cast(value)

# File activemodel/lib/active_model/type/binary.rb, line 18
def cast(value)
  if value.is_a?(Data)
    value.to_s
  else
    super
  end
end

changed_in_place?(raw_old_value, value)

# File activemodel/lib/active_model/type/binary.rb, line 31
def changed_in_place?(raw_old_value, value)
  old_value = deserialize(raw_old_value)
  old_value != value
end

serialize(value)

# File activemodel/lib/active_model/type/binary.rb, line 26
def serialize(value)
  return if value.nil?
  Data.new(super)
end

type()

# File activemodel/lib/active_model/type/binary.rb, line 10
def type
  :binary
end