Class: ActiveRecord::ConnectionAdapters::SQLServer::Utils::Name

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

Overview

Value object to return identifiers from SQL Server names bit.ly/1CZ3EiL Inspired from Rails PostgreSQL::Name adapter object in their own Utils.

Constant Summary collapse

UNQUOTED_SCANNER =
/\]?\./
QUOTED_SCANNER =
/\A\[.*?\]\./
QUOTED_CHECKER =
/\A\[/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Name

Returns a new instance of Name.



19
20
21
22
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 19

def initialize(name)
  @raw_name = name.to_s
  parse_raw_name
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



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

def database
  @database
end

#objectObject (readonly)

Returns the value of attribute object.



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

def object
  @object
end

#raw_nameObject (readonly)

Returns the value of attribute raw_name.



17
18
19
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 17

def raw_name
  @raw_name
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

#serverObject (readonly)

Returns the value of attribute server.



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

def server
  @server
end

Instance Method Details

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



75
76
77
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 75

def ==(other)
  other.class == self.class && other.parts == parts
end

#database_quotedObject



32
33
34
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 32

def database_quoted
  database ? quote(database) : database
end

#fully_qualified?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 44

def fully_qualified?
  qualified_level == :fully
end

#fully_qualified_database_quotedObject



40
41
42
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 40

def fully_qualified_database_quoted
  [server_quoted, database_quoted].compact.join('.')
end

#hashObject



80
81
82
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 80

def hash
  parts.hash
end

#object_quotedObject



24
25
26
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 24

def object_quoted
  quote object
end

#qualified_levelObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 48

def qualified_level
  case parts.compact.size
  when 4
    :fully
  when 3
    :database
  when 2
    :schema
  when 1
    :table
  else
    :none
  end
end

#quotedObject



67
68
69
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 67

def quoted
  parts.map { |p| quote(p) if p }.join('.')
end

#quoted_rawObject



71
72
73
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 71

def quoted_raw
  quote @raw_name
end

#schema_quotedObject



28
29
30
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 28

def schema_quoted
  schema ? quote(schema) : schema
end

#server_quotedObject



36
37
38
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 36

def server_quoted
  server ? quote(server) : server
end

#to_sObject



63
64
65
# File 'lib/active_record/connection_adapters/sqlserver/utils.rb', line 63

def to_s
  quoted
end