cloudcontrol-rails 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cloudcontrol-rails (0.0.4)
4
+ cloudcontrol-rails (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -6,7 +6,7 @@ Override empty database.yml settings with the ENV vars on the cloudControl platt
6
6
 
7
7
  Add the following to your gemfile
8
8
  ~~~
9
- gem "cloudcontrol-rails", :git => "git://github.com/Traxmaxx/cctrl_database_configuration.git"
9
+ gem "cloudcontrol-rails"
10
10
  ~~~
11
11
 
12
12
  And run `bundle install`
@@ -2,8 +2,8 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'cloudcontrol-rails'
5
- s.version = "0.0.4"
6
- s.authors = ["Alexander Rösel"]
5
+ s.version = "0.0.5"
6
+ s.authors = ["Alexander Rösel", "Ivan Kusalic"]
7
7
  s.email = ["info@netzok.net"]
8
8
  s.summary = "Autoload MySQL and Postgres credentials from ENV vars on cloudControl"
9
9
  s.description = "Use credentials set in ENV vars if database.yml credentials are empty. Supports MySQL and ElephantSQL (Postgres) on the cloudControl platform."
@@ -1,12 +1,19 @@
1
1
  module Cloudcontrol
2
- def self.configure_mysql(config, rails_env) # NOTE addons MySQLS and MySQLD
2
+ ADDON_KEYS = { # NOTE addons MySQLS and MySQLD
3
+ 'database' => %w[ MYSQLD_DATABASE MYSQLS_DATABASE ],
4
+ 'host' => %w[ MYSQLD_HOST MYSQLS_HOSTNAME ],
5
+ 'port' => %w[ MYSQLD_PORT MYSQLS_PORT ],
6
+ 'username' => %w[ MYSQLD_USER MYSQLS_USERNAME ],
7
+ 'password' => %w[ MYSQLD_PASSWORD MYSQLS_PASSWORD ],
8
+ }
9
+
10
+ def self.configure_mysql(config, rails_env)
3
11
  config[rails_env].each do |key, value|
4
12
  if value.nil?
5
- if key == 'username' # NOTE auto match breaks on username so we need to look for it manually
6
- config[rails_env][key] = ENV['MYSQLD_USER'] || ENV['MYSQLS_USER'] || nil
7
- else
8
- config[rails_env][key] = ENV["MYSQLD_#{ key.upcase }"] || ENV["MYSQLS_#{ key.upcase }"] || nil
9
- end
13
+ new_value = ADDON_KEYS[key].reduce(nil) { |acc, e| acc ||= ENV[e] }
14
+ new_value = new_value.to_i if key == 'port' && new_value
15
+
16
+ config[rails_env][key] = new_value
10
17
  end
11
18
  end
12
19
 
@@ -5,9 +5,11 @@ require 'yaml'
5
5
  require 'spec_helper'
6
6
  require 'cloudcontrol/cloudcontrol'
7
7
 
8
+ # TODO refactor using shared examples/contexts
9
+
8
10
  describe "Cloudcontrol" do
9
- let(:db_config_dev) { [ adapter ] + [ 'env' ] * 5 }
10
- let(:db_config_prod) { [ adapter ] + [ 'env' ] * 5 }
11
+ let(:db_config_dev) { [ adapter, 'env', 42, 'env', 'env', 'env' ] }
12
+ let(:db_config_prod) { [ adapter, 'env', 42, 'env', 'env', 'env' ] }
11
13
 
12
14
  let(:database_yml) do
13
15
  yml = <<END
@@ -47,7 +49,7 @@ end
47
49
  {
48
50
  "adapter" => adapter,
49
51
  "host" => 'env',
50
- "port" => 'env',
52
+ "port" => 42,
51
53
  "database" => 'env',
52
54
  "username" => 'env',
53
55
  "password" => 'env',
@@ -57,13 +59,23 @@ end
57
59
  before do
58
60
  ENV = {
59
61
  'RAILS_ENV' => "production",
60
- 'MYSQLS_HOST' => "env",
61
- 'MYSQLS_PORT' => "env",
62
+ 'MYSQLS_HOSTNAME' => "env",
63
+ 'MYSQLS_PORT' => "42",
62
64
  'MYSQLS_DATABASE' => "env",
63
- 'MYSQLS_USER' => "env",
65
+ 'MYSQLS_USERNAME' => "env",
64
66
  'MYSQLS_PASSWORD' => "env",
65
67
  'ELEPHANTSQL_URL' => 'postgres://env:env@env.env.env:42/env',
66
68
  }
69
+
70
+ #ENV = { # TODO
71
+ #'RAILS_ENV' => "production",
72
+ #'MYSQLD_HOST' => "env",
73
+ #'MYSQLD_PORT' => "42",
74
+ #'MYSQLD_DATABASE' => "env",
75
+ #'MYSQLD_USER' => "env",
76
+ #'MYSQLD_PASSWORD' => "env",
77
+ #'ELEPHANTSQL_URL' => 'postgres://env:env@env.env.env:42/env',
78
+ #}
67
79
  end
68
80
 
69
81
  describe "MySQL" do
@@ -181,7 +193,7 @@ end
181
193
  end
182
194
 
183
195
  describe "for production" do
184
- let(:db_config_prod) { [ adapter, 'host', '42', 'db', nil, nil ] }
196
+ let(:db_config_prod) { [ adapter, 'host', 42, 'db', nil, nil ] }
185
197
 
186
198
  it "should return proper value" do
187
199
  env = 'production'
@@ -195,7 +207,7 @@ end
195
207
  end
196
208
 
197
209
  describe "for development" do
198
- let(:db_config_dev) { [ adapter, 'host', '42', 'db', nil, nil ] }
210
+ let(:db_config_dev) { [ adapter, 'host', 42, 'db', nil, nil ] }
199
211
 
200
212
  it "should return proper value" do
201
213
  env = 'development'
@@ -210,7 +222,7 @@ end
210
222
  end
211
223
 
212
224
  describe "with fully provided values" do
213
- let(:db_config_prod) { [ adapter, 'host', '42', 'db', 'username', 'pass' ] }
225
+ let(:db_config_prod) { [ adapter, 'host', 42, 'db', 'username', 'pass' ] }
214
226
  let(:expected_res) do
215
227
  {
216
228
  "adapter"=>adapter,
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudcontrol-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Alexander Rösel
9
+ - Ivan Kusalic
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
13
+ date: 2013-01-16 00:00:00.000000000 Z
13
14
  dependencies: []
14
15
  description: Use credentials set in ENV vars if database.yml credentials are empty.
15
16
  Supports MySQL and ElephantSQL (Postgres) on the cloudControl platform.