dbenvy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7c2ca8dc51341425a9b3f00a5d58f9819b3aa89d
4
+ data.tar.gz: c815f682f306ecf0f5c6a2de078ba9d067e63054
5
+ SHA512:
6
+ metadata.gz: b999b5909f36bfcb42a55013bcb7cf8bdf721ee92167f5705a7a42ad2cb0b8cf31505479511c294a0875c4a5f31fdabc21151f2b76a54db445b7c6d53848f056
7
+ data.tar.gz: 08fb0c39d6df36f85ca63c8b0b2eae8ff46bb5d30dc9c9115b9d3688c11bc7d2c1fbc898a611c257c58f33681468bed9aba18b221f93859c7d3b5265a977b0f5
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dbenvy.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ed Robinson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Dbenvy
2
+
3
+ Load DB info from the environment
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dbenvy'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ Add the following to your database.yml file and set the DATABASE_URL environment variable
20
+
21
+ ```
22
+ <% DBEnvy.yaml %>
23
+ ```
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/reevoo/dbenvy/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task release: :spec
data/dbenvy.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dbenvy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dbenvy"
8
+ spec.version = DBEnvy::VERSION
9
+ spec.authors = ["Ed Robinson"]
10
+ spec.email = ["ed@reevoo.com"]
11
+ spec.summary = %q{Load DB info from the environment}
12
+ spec.description = %q{Use DBEnvy to parse DATABASE_URL and shim the info into a database.yml}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "rack"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ end
data/lib/dbenvy.rb ADDED
@@ -0,0 +1,53 @@
1
+ require "dbenvy/version"
2
+ require 'uri'
3
+ require 'rack/utils'
4
+ require 'yaml'
5
+
6
+ class DBEnvy
7
+ def self.to_hash
8
+ new.to_hash
9
+ end
10
+
11
+ def self.yaml
12
+ new.yaml
13
+ end
14
+
15
+ attr_accessor :uri
16
+
17
+ def initialize
18
+ self.uri = URI.parse ENV['DATABASE_URL'] if ENV['DATABASE_URL']
19
+ end
20
+
21
+ def yaml
22
+ YAML.dump( { rails_env => to_hash } ) if uri && rails_env
23
+ end
24
+
25
+ def to_hash
26
+ credentials.merge options
27
+ end
28
+
29
+ private
30
+
31
+ def rails_env
32
+ ENV['RAILS_ENV']
33
+ end
34
+
35
+ def credentials
36
+ {
37
+ "adapter" => uri.scheme,
38
+ "username" => uri.user,
39
+ "password" => uri.password,
40
+ "host" => uri.host,
41
+ "port" => uri.port,
42
+ "database" => database,
43
+ }
44
+ end
45
+
46
+ def options
47
+ Rack::Utils.parse_nested_query uri.query
48
+ end
49
+
50
+ def database
51
+ uri.path.dup.tap { |p| p.slice!("/") }
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ class DBEnvy
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,91 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, consider making
12
+ # a separate helper file that requires the additional dependencies and performs
13
+ # the additional setup, and require it from the spec files that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
54
+ # For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+ require 'dbenvy'
3
+
4
+ describe DBEnvy do
5
+ describe '.to_hash' do
6
+ context 'with a DATABSE_URL in the environment' do
7
+
8
+ let(:hash) { described_class.to_hash }
9
+
10
+ before do
11
+ ENV['DATABASE_URL'] = 'mysql2://susan:sekret@127.0.0.1:3306/reevoo_live?encoding=utf8&view_options[awesome_database]=awesome_live'
12
+ end
13
+
14
+ it 'extracts the adapter' do
15
+ expect(hash['adapter']).to eq 'mysql2'
16
+ end
17
+
18
+ it 'extracts the host' do
19
+ expect(hash['host']).to eq '127.0.0.1'
20
+ end
21
+
22
+ it 'extracts the database name' do
23
+ expect(hash['database']).to eq 'reevoo_live'
24
+ end
25
+
26
+ it 'extracts the username' do
27
+ expect(hash['username']).to eq 'susan'
28
+ end
29
+
30
+ it 'extracts the password' do
31
+ expect(hash['password']).to eq 'sekret'
32
+ end
33
+
34
+ it 'extracts the port' do
35
+ expect(hash['port']).to eq 3306
36
+ end
37
+
38
+ it 'extracts some standard query params' do
39
+ expect(hash['encoding']).to eq 'utf8'
40
+ end
41
+ end
42
+ end
43
+
44
+ describe '.yaml' do
45
+ let(:yaml) { described_class.yaml }
46
+
47
+ context 'when the DATABASE_URL is not set' do
48
+
49
+ before do
50
+ ENV['RAILS_ENV'] = nil
51
+ ENV['DATABASE_URL'] = nil
52
+ end
53
+
54
+ it 'is nil' do
55
+ expect(yaml).to be_nil
56
+ end
57
+ end
58
+
59
+ context 'when RAILS_ENV is set' do
60
+ before do
61
+ ENV['RAILS_ENV'] = 'production'
62
+ ENV['DATABASE_URL'] = 'mysql2://reevoo:secret@db456.reevoover.com:3306/reevoo_awesome?encoding=utf8&view_options[awesome_database]=awesome_live&socket=%2Fvar%2Frun%2Fmysqld%2Fmysqld.sock'
63
+ end
64
+
65
+ it 'uses the current rails env and extracts the database info' do
66
+ expect(YAML.load(yaml)).to eq(
67
+ "production" => {
68
+ "adapter" => "mysql2",
69
+ "username" => "reevoo",
70
+ "port" => 3306,
71
+ "host" => "db456.reevoover.com",
72
+ "database" => "reevoo_awesome",
73
+ "password" => "secret",
74
+ "encoding" => "utf8",
75
+ "socket" => "/var/run/mysqld/mysqld.sock",
76
+ "view_options" => {"awesome_database" => "awesome_live"}})
77
+ end
78
+ end
79
+ end
80
+ end
81
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dbenvy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ed Robinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Use DBEnvy to parse DATABASE_URL and shim the info into a database.yml
70
+ email:
71
+ - ed@reevoo.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - dbenvy.gemspec
84
+ - lib/dbenvy.rb
85
+ - lib/dbenvy/version.rb
86
+ - spec/spec_helper.rb
87
+ - spec/unit/dbenvy_spec.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Load DB info from the environment
112
+ test_files:
113
+ - spec/spec_helper.rb
114
+ - spec/unit/dbenvy_spec.rb