class ActiveRecord::ConnectionAdapters::SQLServer::Utils::Name

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

Constants

QUOTED_CHECKER
QUOTED_SCANNER
SEPARATOR
UNQUOTED_SCANNER

Attributes

database[R]
object[R]
raw_name[R]
schema[R]
server[R]

Public Class Methods

new(name) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 23
def initialize(name)
  @raw_name = name.to_s
  parse_raw_name
end

Public Instance Methods

==(o) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 64
def ==(o)
  o.class == self.class && o.parts == parts
end
Also aliased as: eql?
database_quoted() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 36
def database_quoted
  database ? quote(database) : database
end
eql?(o)
Alias for: ==
fully_qualified?() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 48
def fully_qualified?
  parts.compact.size == 4
end
fully_qualified_database_quoted() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 44
def fully_qualified_database_quoted
  [server_quoted, database_quoted].compact.join(SEPARATOR)
end
hash() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 69
def hash
  parts.hash
end
object_quoted() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 28
def object_quoted
  quote object
end
quoted() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 56
def quoted
  parts.map{ |p| quote(p) if p }.join SEPARATOR
end
quoted_raw() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 60
def quoted_raw
  quote @raw_name
end
schema_quoted() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 32
def schema_quoted
  schema ? quote(schema) : schema
end
server_quoted() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 40
def server_quoted
  server ? quote(server) : server
end
to_s() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 52
def to_s
  quoted
end

Protected Instance Methods

parse_raw_name() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 75
def parse_raw_name
  @parts = []
  return if raw_name.blank?
  scanner = StringScanner.new(raw_name)
  matched = scanner.exist?(QUOTED_CHECKER) ? scanner.scan_until(QUOTED_SCANNER) : scanner.scan_until(UNQUOTED_SCANNER)
  while matched
    part = matched[0..-2]
    @parts << (part.blank? ? nil : unquote(part))
    matched = scanner.exist?(QUOTED_CHECKER) ? scanner.scan_until(QUOTED_SCANNER) : scanner.scan_until(UNQUOTED_SCANNER)
  end
  case @parts.length
  when 3
    @server, @database, @schema = @parts
  when 2
    @database, @schema = @parts
  when 1
    @schema = @parts.first
  end
  rest = scanner.rest
  rest = rest.starts_with?('.') ? rest[1..-1] : rest[0..-1]
  @object = unquote(rest)
  @parts << @object
end
parts() click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 111
def parts
  @parts
end
quote(part) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 99
def quote(part)
  part =~ /\A\[.*\]\z/ ? part : "[#{part.to_s.gsub(']', ']]')}]"
end
unquote(part) click to toggle source
# File lib/active_record/connection_adapters/sqlserver/utils.rb, line 103
def unquote(part)
  if part && part.start_with?('[')
    part[1..-2]
  else
    part
  end
end