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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4252f9c1907733834ec22c952d74dd28e9e320ed274202cd20e4e672a9fd0746
4
- data.tar.gz: 267708e01b05d2c1a1face1c19c6ae6f74ff726cd330f3cf87f104c6fee4a84a
3
+ metadata.gz: cc90c4ac36e6d74ded195f11d6c39b556a73de7e813f46273c4dfb85089ed7d0
4
+ data.tar.gz: 0444f199ea3d6a5f2136adbc8fb3bf77406c42d0aa7e9818d07c56c4e852ddc7
5
5
  SHA512:
6
- metadata.gz: 59c4d07bc30ac0b1cd120aea051694b2cc81533ec8c7575606815b548397e4fb17cb3f53cbe7ff314018198ae6d844363200431a46d6d6e948a85dce239cae2d
7
- data.tar.gz: 6a9997690b9ecdbe6a0095b5f310cc5eab970fcf8d4307295a32d2b0d4653f3a056627e3ca4e3cd0b0092239facc110c5cc23d00b432832e766fca46385e59d0
6
+ metadata.gz: e4692e5d5b597391b88aa7e3f6aa41091ed8650edde75760669fdc46c143c396cdd1981101a330154f159fb394ce569b5c55b08061d4ade1284244579f118a3d
7
+ data.tar.gz: 8567c7b3e11ed9302ae8b07568b938fb0613975a8168c3ce2d5aa9e8df84fd523d114cd31e63680f590325e40cfc87623ca9cd944cd30a7c61dbb8328eb9347b
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ .rspec_status
@@ -1,6 +1,17 @@
1
- sudo: false
2
1
  language: ruby
2
+ sudo: false
3
3
  rvm:
4
- - 2.3.2
5
- env: COVERAGE=true
6
- before_install: gem install bundler -v 1.13.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
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in activerecord-migrations.gemspec
4
3
  gemspec
5
4
 
6
5
  group :development do
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] = 'postgres'
62
+ environment[:adapter] = 'postgresql'
63
63
  when 'mysql'
64
64
  environment[:adapter] = 'mysql2'
65
65
  else
66
- raise ArgumentError.new("Unsupported database access: #{uri.scheme.inspect}")
66
+ environment[:adapter] = uri.scheme
67
67
  end
68
68
 
69
69
  if username = uri.user
@@ -20,6 +20,6 @@
20
20
 
21
21
  module ActiveRecord
22
22
  module Configurations
23
- VERSION = "0.1.0"
23
+ VERSION = "0.2.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-configurations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams