Sha256: fb6454679c36067470d488453242c237f55585c4876d6b5bed28f896ee845ba1

Contents?: true

Size: 871 Bytes

Versions: 106

Compression:

Stored size: 871 Bytes

Contents

# frozen_string_literal: true

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.unpack1("H*")
        end

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

Version data entries

106 entries across 102 versions & 10 rubygems

Version Path
activemodel-6.1.7.10 lib/active_model/type/binary.rb
activemodel-6.1.7.9 lib/active_model/type/binary.rb
activemodel-6.1.7.8 lib/active_model/type/binary.rb
activemodel-6.1.7.7 lib/active_model/type/binary.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-7.0.2.3/lib/active_model/type/binary.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-6.1.6.1/lib/active_model/type/binary.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-7.0.3.1/lib/active_model/type/binary.rb
activemodel-6.1.7.6 lib/active_model/type/binary.rb
activemodel-6.1.7.5 lib/active_model/type/binary.rb
activemodel-6.1.7.4 lib/active_model/type/binary.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activemodel-6.1.6.1/lib/active_model/type/binary.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activemodel-7.0.3.1/lib/active_model/type/binary.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activemodel-7.0.2.3/lib/active_model/type/binary.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/binary.rb
activemodel-7.0.4.3 lib/active_model/type/binary.rb
activemodel-6.1.7.3 lib/active_model/type/binary.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/binary.rb
activemodel-6.1.7.2 lib/active_model/type/binary.rb
activemodel-7.0.4.2 lib/active_model/type/binary.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/type/binary.rb