Sha256: 5ae638d5fef0a5a449b880e3ac758ee357ecb541f1b9c0aa4363069e343e9f45

Contents?: true

Size: 873 Bytes

Versions: 51

Compression:

Stored size: 873 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

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

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

        def to_s
          @value
        end
        alias_method :to_str, :to_s

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

        def ==(other)
          other == to_s || super
        end
      end
    end
  end
end

Version data entries

51 entries across 50 versions & 8 rubygems

Version Path
activerecord-4.2.11.3 lib/active_record/type/binary.rb
activerecord-4.2.11.2 lib/active_record/type/binary.rb
activerecord-4.2.11.1 lib/active_record/type/binary.rb
activerecord-4.2.11 lib/active_record/type/binary.rb
activerecord-4.2.10 lib/active_record/type/binary.rb
activerecord-4.2.10.rc1 lib/active_record/type/binary.rb
activerecord-4.2.9 lib/active_record/type/binary.rb
activerecord-4.2.9.rc2 lib/active_record/type/binary.rb
activerecord-4.2.9.rc1 lib/active_record/type/binary.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-4.2.8/lib/active_record/type/binary.rb
activerecord-4.2.8 lib/active_record/type/binary.rb
activerecord-4.2.8.rc1 lib/active_record/type/binary.rb
activerecord-4.2.7.1 lib/active_record/type/binary.rb
activerecord-4.2.7 lib/active_record/type/binary.rb
activerecord-4.2.7.rc1 lib/active_record/type/binary.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-4.2.6/lib/active_record/type/binary.rb
activerecord-4.2.6 lib/active_record/type/binary.rb
activerecord-4.2.6.rc1 lib/active_record/type/binary.rb
activerecord-4.2.5.2 lib/active_record/type/binary.rb
activejob-lock-0.0.2 rails/activerecord/lib/active_record/type/binary.rb