Sha256: a3507fe384f8f719c59efb2fba58a6e58d626a6e1a7ea39ebeebf10b12a00623

Contents?: true

Size: 842 Bytes

Versions: 38

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

38 entries across 37 versions & 5 rubygems

Version Path
activemodel-5.0.7.2 lib/active_model/type/binary.rb
activemodel-5.0.7.1 lib/active_model/type/binary.rb
activemodel-5.0.7 lib/active_model/type/binary.rb
activemodel-5.0.6 lib/active_model/type/binary.rb
activemodel-5.0.6.rc1 lib/active_model/type/binary.rb
activemodel-5.0.5 lib/active_model/type/binary.rb
activemodel-5.0.5.rc2 lib/active_model/type/binary.rb
activemodel-5.0.5.rc1 lib/active_model/type/binary.rb
tdiary-5.0.5 vendor/bundle/gems/activemodel-5.0.2/lib/active_model/type/binary.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activemodel-5.0.2/lib/active_model/type/binary.rb
activemodel-5.0.4 lib/active_model/type/binary.rb
activemodel-5.0.4.rc1 lib/active_model/type/binary.rb
activemodel-5.0.3 lib/active_model/type/binary.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activemodel-5.0.2/lib/active_model/type/binary.rb
tdiary-5.0.4 vendor/bundle/gems/activemodel-5.0.2/lib/active_model/type/binary.rb
activemodel-5.0.2 lib/active_model/type/binary.rb
activemodel-5.0.2.rc1 lib/active_model/type/binary.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/type/binary.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/type/binary.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/type/binary.rb