Class: ActiveRecord::ConnectionAdapters::SQLServer::Type::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlserver/type/data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, type) ⇒ Data

Returns a new instance of Data.



12
13
14
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 12

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

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 8

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



8
9
10
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 8

def value
  @value
end

Class Method Details

.from_msgpack_ext(string) ⇒ Object



40
41
42
43
44
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 40

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

  Data.new(value, type.constantize)
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:



29
30
31
32
33
34
35
36
37
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 29

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

#inspectObject



25
26
27
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 25

def inspect
  @value.inspect
end

#quotedObject



16
17
18
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 16

def quoted
  type.quoted(@value)
end

#to_msgpack_extObject



46
47
48
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 46

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

#to_sObject Also known as: to_str



20
21
22
# File 'lib/active_record/connection_adapters/sqlserver/type/data.rb', line 20

def to_s
  @value
end