jdbc-url 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/jdbc-url.rb +37 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 82cda77a5e52d20d5df8a6a554d93263e6962d50
|
4
|
+
data.tar.gz: ce9b593f17c083d02d57c730b2e0ab5ec093637d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0025cfb092c3406a383e380a80a4dabef58e261b74dcd13f7202e219a3028071a461385166cbb188f83520cb1704e839544cfb3d3d3285c015eaede347e7ae71
|
7
|
+
data.tar.gz: 1e2afb90e9a8d996af20d1295c709a92493e669b6a990e97f03306b3acfaf95e10495574c177f2ab9b968aef737fdf077232ffcf4d8a912d7991b6b497df124b
|
data/lib/jdbc-url.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module JdbcUrl
|
2
|
+
def self.from_database_url
|
3
|
+
from_env_var('DATABASE_URL')
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.from_env_var(var, default=nil)
|
7
|
+
from(ENV[var] || default)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.from(db_url)
|
11
|
+
db_protocol = db_url.split(':')[0]
|
12
|
+
jdbc_protocol = case db_protocol
|
13
|
+
when 'postgres' then 'postgresql'
|
14
|
+
else db_protocol
|
15
|
+
end
|
16
|
+
|
17
|
+
db_server = db_url.split('@')[1]
|
18
|
+
db_host = db_server.split(':')[0]
|
19
|
+
db_port = db_server.split(':')[1].split('/')[0]
|
20
|
+
db_name = db_server.split(':')[1].split('/')[1].split('?')[0]
|
21
|
+
|
22
|
+
db_creds = db_url.split('@')[0].gsub('postgres://', '')
|
23
|
+
db_user = db_creds.split(':')[0]
|
24
|
+
db_pass = db_creds.split(':')[1]
|
25
|
+
|
26
|
+
db_params = []
|
27
|
+
if db_url.include?("#{db_name}?")
|
28
|
+
db_params << db_url.split("#{db_name}?")[1]
|
29
|
+
end
|
30
|
+
|
31
|
+
db_params << "user=#{db_user}"
|
32
|
+
db_params << "password=#{db_pass}"
|
33
|
+
db_params << "sslmode=require" if jdbc_protocol == 'postgresql'
|
34
|
+
|
35
|
+
"jdbc:#{jdbc_protocol}://#{db_host}:#{db_port}/#{db_name}?#{db_params.join('&')}"
|
36
|
+
end
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jdbc-url
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joe Kutner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A library for creating JDBC URLs from standard Database URLs
|
14
|
+
email: jpkutner@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/jdbc-url.rb
|
20
|
+
homepage: http://github.com/jkutner/jdbc-url
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: A library for creating JDBC URLs
|
44
|
+
test_files: []
|
45
|
+
has_rdoc:
|