跳至內容 跳至搜尋

Active Model Binary Type

二進位資料表徵的屬性類型。此類型已在 :binary 鍵下註冊。

非字串值會使用其 to_s 方法轉換成字串。

方法
B
C
S
T

執行個體公開方法

binary?()

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

cast(value)

# File activemodel/lib/active_model/type/binary.rb, line 20
def cast(value)
  if value.is_a?(Data)
    value.to_s
  else
    value = super
    value = value.b if ::String === value && value.encoding != Encoding::BINARY
    value
  end
end

changed_in_place?(raw_old_value, value)

# File activemodel/lib/active_model/type/binary.rb, line 35
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 30
def serialize(value)
  return if value.nil?
  Data.new(super)
end

type()

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