Sha256: 942165205b8e891606c4001d713af854a4e78719b8b2b63995e36dd8c21638bd

Contents?: true

Size: 842 Bytes

Versions: 22

Compression:

Stored size: 842 Bytes

Contents

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

      def binary?
        true
      end

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

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

      def changed_in_place?(raw_old_value, value)
        old_value = deserialize(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

22 entries across 22 versions & 2 rubygems

Version Path
activemodel-5.1.7 lib/active_model/type/binary.rb
activemodel-5.1.7.rc1 lib/active_model/type/binary.rb
activemodel-5.1.6.2 lib/active_model/type/binary.rb
activemodel-5.1.6.1 lib/active_model/type/binary.rb
activemodel-5.1.6 lib/active_model/type/binary.rb
tdiary-5.0.8 vendor/bundle/gems/activemodel-5.1.5/lib/active_model/type/binary.rb
activemodel-5.1.5 lib/active_model/type/binary.rb
activemodel-5.1.5.rc1 lib/active_model/type/binary.rb
activemodel-5.1.4 lib/active_model/type/binary.rb
activemodel-5.1.4.rc1 lib/active_model/type/binary.rb
activemodel-5.1.3 lib/active_model/type/binary.rb
activemodel-5.1.3.rc3 lib/active_model/type/binary.rb
activemodel-5.1.3.rc2 lib/active_model/type/binary.rb
activemodel-5.1.3.rc1 lib/active_model/type/binary.rb
tdiary-5.0.5 vendor/bundle/gems/activemodel-5.1.2/lib/active_model/type/binary.rb
activemodel-5.1.2 lib/active_model/type/binary.rb
activemodel-5.1.2.rc1 lib/active_model/type/binary.rb
activemodel-5.1.1 lib/active_model/type/binary.rb
activemodel-5.1.0 lib/active_model/type/binary.rb
activemodel-5.1.0.rc2 lib/active_model/type/binary.rb