Sha256: db6b0d5718faa554f01ee00db20d11ee7c82d6413bd781f0a2e7700aa3491549

Contents?: true

Size: 1.26 KB

Versions: 23

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module SQLServer
      module Type
        class Data
          attr_reader :value, :type

          delegate :sub, to: :value

          def initialize(value, type)
            @value, @type = value, type
          end

          def quoted
            type.quoted(@value)
          end

          def to_s
            @value
          end
          alias_method :to_str, :to_s

          def inspect
            @value.inspect
          end

          def eql?(other)
            # Support comparing `Type::Char`, `Type::Varchar` and `VarcharMax` with strings.
            # This happens when we use enum with string columns.
            if other.is_a?(::String)
              return type.is_a?(ActiveRecord::ConnectionAdapters::SQLServer::Type::String) && value == other
            end

            self.class == other.class && value == other.value
          end
          alias :== :eql?

          def self.from_msgpack_ext(string)
            type, value = string.chomp!("msgpack_ext").split(',')

            Data.new(value, type.constantize)
          end

          def to_msgpack_ext
            [type.class.to_s, value].join(',') + "msgpack_ext"
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
activerecord-sqlserver-adapter-7.1.11 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.2.4 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-8.0.2 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.10 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.2.3 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-8.0.1 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-8.0.0 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.2.2 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.9 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.8 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.2.1 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.2.0 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.7 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.6 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.5 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.4 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.3 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.2 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.1 lib/active_record/connection_adapters/sqlserver/type/data.rb
activerecord-sqlserver-adapter-7.1.0 lib/active_record/connection_adapters/sqlserver/type/data.rb