activerecord-configurations 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +15 -4
- data/Gemfile +0 -1
- data/README.md +46 -0
- data/lib/active_record/configurations.rb +2 -2
- data/lib/active_record/configurations/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc90c4ac36e6d74ded195f11d6c39b556a73de7e813f46273c4dfb85089ed7d0
|
4
|
+
data.tar.gz: 0444f199ea3d6a5f2136adbc8fb3bf77406c42d0aa7e9818d07c56c4e852ddc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4692e5d5b597391b88aa7e3f6aa41091ed8650edde75760669fdc46c143c396cdd1981101a330154f159fb394ce569b5c55b08061d4ade1284244579f118a3d
|
7
|
+
data.tar.gz: 8567c7b3e11ed9302ae8b07568b938fb0613975a8168c3ce2d5aa9e8df84fd523d114cd31e63680f590325e40cfc87623ca9cd944cd30a7c61dbb8328eb9347b
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
2
|
+
sudo: false
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
|
6
|
-
|
4
|
+
- 2.1
|
5
|
+
- 2.2
|
6
|
+
- 2.3
|
7
|
+
- 2.4
|
8
|
+
- ruby-head
|
9
|
+
- jruby-head
|
10
|
+
- rbx-2
|
11
|
+
env:
|
12
|
+
- COVERAGE=true
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: "rbx-2"
|
16
|
+
- rvm: "ruby-head"
|
17
|
+
- rvm: "jruby-head"
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -6,6 +6,12 @@ This gem replaces the default ActiveRecord configurations system which typically
|
|
6
6
|
[![Code Climate](https://codeclimate.com/github/ioquatix/activerecord-configurations.svg)](https://codeclimate.com/github/ioquatix/activerecord-configurations)
|
7
7
|
[![Coverage Status](https://coveralls.io/repos/ioquatix/activerecord-configurations/badge.svg)](https://coveralls.io/r/ioquatix/activerecord-configurations)
|
8
8
|
|
9
|
+
## Motivation
|
10
|
+
|
11
|
+
The standard YAML file technique of specifying database configurations is cumbersome at best, and really only works well for a single database connection: there is no isolation between different sets of connections, and it's not possible to specify multiple `DATABASE_URL` values.
|
12
|
+
|
13
|
+
We needed something to streamline and minimize the amount of configuration in this sensitive area of deployment. Making a mistake in a production system is a big problem. This is achieved by testing and convention over configuration.
|
14
|
+
|
9
15
|
## Installation
|
10
16
|
|
11
17
|
Add this line to your application's Gemfile:
|
@@ -21,9 +27,49 @@ Add something like this to `db/environment.rb`
|
|
21
27
|
```ruby
|
22
28
|
require 'active_record/configurations'
|
23
29
|
|
30
|
+
class ActiveRecord::Base
|
31
|
+
extend ActiveRecord::Configurations
|
32
|
+
|
33
|
+
configure(:production) do
|
34
|
+
prefix 'library'
|
35
|
+
adapter 'postgres'
|
36
|
+
end
|
24
37
|
|
38
|
+
configure(:development, parent: :production)
|
39
|
+
end
|
40
|
+
|
41
|
+
# pp ActiveRecord::Base.configurations
|
25
42
|
```
|
26
43
|
|
44
|
+
This will setup the `development` and `production` configurations, which can be overridden by specifying the `LIBRARY_DSN` environment variable.
|
45
|
+
|
46
|
+
### Multiple Databases
|
47
|
+
|
48
|
+
You can easily have more than one database connection.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
class UsersModel < ActiveRecord::Base
|
52
|
+
self.abstract_class = true
|
53
|
+
|
54
|
+
extend ActiveRecord::Configurations
|
55
|
+
|
56
|
+
configure(:production) do
|
57
|
+
prefix 'users'
|
58
|
+
adapter 'mysql2'
|
59
|
+
end
|
60
|
+
|
61
|
+
configure(:development, parent: :production)
|
62
|
+
end
|
63
|
+
|
64
|
+
# pp UsersModel.configurations
|
65
|
+
|
66
|
+
class User < UsersModel
|
67
|
+
# ...
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
As this has a different prefix, the connection can be overridden by specifying `USERS_DSN`.
|
72
|
+
|
27
73
|
## Contributing
|
28
74
|
|
29
75
|
1. Fork it
|
@@ -59,11 +59,11 @@ module ActiveRecord
|
|
59
59
|
|
60
60
|
case uri.scheme
|
61
61
|
when 'postgres'
|
62
|
-
environment[:adapter] = '
|
62
|
+
environment[:adapter] = 'postgresql'
|
63
63
|
when 'mysql'
|
64
64
|
environment[:adapter] = 'mysql2'
|
65
65
|
else
|
66
|
-
|
66
|
+
environment[:adapter] = uri.scheme
|
67
67
|
end
|
68
68
|
|
69
69
|
if username = uri.user
|