rails-database-url 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/Rakefile +1 -0
- data/lib/rails-database-url.rb +46 -0
- data/lib/rails-database-url/version.rb +3 -0
- data/rails-database-url.gemspec +22 -0
- metadata +69 -0
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "rails-database-url/version"
|
2
|
+
require "erb"
|
3
|
+
|
4
|
+
module RailsDatabaseUrl
|
5
|
+
def self.set_database_url
|
6
|
+
return if ENV["DATABASE_URL"]
|
7
|
+
ENV["DATABASE_URL"] = config_to_url(db_config)
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def self.rails_loaded?
|
12
|
+
const_defined?(:Rails)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.env
|
16
|
+
return Rails.env if rails_loaded?
|
17
|
+
ENV["RAILS_ENV"] || ENV["RACK_ENV"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.config_file
|
21
|
+
File.expand_path("./config/database.yml")
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.db_config
|
25
|
+
config = YAML::load(ERB.new(IO.read(config_file)).result)
|
26
|
+
config[env]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.config_to_url(config)
|
30
|
+
if config["username"] || config["password"]
|
31
|
+
user_info = [ config["username"], config["password"] ].join(":")
|
32
|
+
else
|
33
|
+
user_info = nil
|
34
|
+
end
|
35
|
+
URI::Generic.new(config["adapter"],
|
36
|
+
user_info,
|
37
|
+
config["hostname"] || "localhost",
|
38
|
+
config["port"],
|
39
|
+
nil,
|
40
|
+
"/#{config["database"]}",
|
41
|
+
nil,
|
42
|
+
nil,
|
43
|
+
nil).to_s
|
44
|
+
end
|
45
|
+
end
|
46
|
+
RailsDatabaseUrl.set_database_url
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "rails-database-url/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "rails-database-url"
|
7
|
+
s.version = RailsDatabaseUrl::VERSION
|
8
|
+
s.authors = ["Glenn Gillen"]
|
9
|
+
s.email = ["me@glenngillen.com"]
|
10
|
+
s.homepage = "https://github.com/glenngillen/rails-database-url"
|
11
|
+
s.summary = %q{Sets DATABASE_URL to the apprpriate value from database.yml}
|
12
|
+
s.description = %q{Sets DATABASE_URL, if it's not set already, to the appropriate value out of the Rails config/database.yml}
|
13
|
+
|
14
|
+
s.rubyforge_project = "rails-database-url"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_development_dependency "rake"
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-database-url
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Glenn Gillen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70321480030700 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70321480030700
|
25
|
+
description: Sets DATABASE_URL, if it's not set already, to the appropriate value
|
26
|
+
out of the Rails config/database.yml
|
27
|
+
email:
|
28
|
+
- me@glenngillen.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Rakefile
|
36
|
+
- lib/rails-database-url.rb
|
37
|
+
- lib/rails-database-url/version.rb
|
38
|
+
- rails-database-url.gemspec
|
39
|
+
homepage: https://github.com/glenngillen/rails-database-url
|
40
|
+
licenses: []
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ! '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
hash: -349217692650484013
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
hash: -349217692650484013
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project: rails-database-url
|
65
|
+
rubygems_version: 1.8.15
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Sets DATABASE_URL to the apprpriate value from database.yml
|
69
|
+
test_files: []
|