Sha256: 066080020e182046532e13f076504bc1ff973a181de190dbcfc642f9a577e1e4

Contents?: true

Size: 622 Bytes

Versions: 1

Compression:

Stored size: 622 Bytes

Contents

module ActiveRecord
  module Type
    class Binary < Value # :nodoc:
      def type
        :binary
      end

      def binary?
        true
      end

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

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

      class Data # :nodoc:
        def initialize(value)
          @value = value.to_s
        end

        def to_s
          @value
        end

        def hex
          @value.unpack('H*')[0]
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-4.2.0.beta1 lib/active_record/type/binary.rb