Class: Rsconn::JdbcUrl

Inherits:
Object
  • Object
show all
Defined in:
lib/rsconn/jdbc_url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ JdbcUrl

Returns a new instance of JdbcUrl.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rsconn/jdbc_url.rb', line 5

def initialize(url)
  @url = url
  @host = @url.split('//').last.split(':').first
  @port = @url.split(':').last.split('/').first.to_i
  @database = @url.split('/').last.split('?').first

  db_type = @url.split(':')[1]

  if db_type != 'postgresql'
    fail ArgumentError, 'Only works with a "postgresql" JDBC URL'
  end
end

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



3
4
5
# File 'lib/rsconn/jdbc_url.rb', line 3

def database
  @database
end

#hostObject (readonly)

Returns the value of attribute host.



3
4
5
# File 'lib/rsconn/jdbc_url.rb', line 3

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



3
4
5
# File 'lib/rsconn/jdbc_url.rb', line 3

def port
  @port
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/rsconn/jdbc_url.rb', line 3

def url
  @url
end