Active Model Binary Type

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

Instance Public methods

binary?()

📝 Source code
# File activemodel/lib/active_model/type/binary.rb, line 16
      def binary?
        true
      end
🔎 See on GitHub

cast(value)

📝 Source code
# 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
🔎 See on GitHub

changed_in_place?(raw_old_value, value)

📝 Source code
# 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
🔎 See on GitHub

serialize(value)

📝 Source code
# File activemodel/lib/active_model/type/binary.rb, line 30
      def serialize(value)
        return if value.nil?
        Data.new(super)
      end
🔎 See on GitHub

type()

📝 Source code
# File activemodel/lib/active_model/type/binary.rb, line 12
      def type
        :binary
      end
🔎 See on GitHub