otr-activerecord 1.4.2 → 2.0.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: c8dad01fcadb48149aac6d50f0e66507bab5bb35bfa42af74d5c4f35a6706ef4
4
- data.tar.gz: 2abf82a804042bfb986cef869c7be5f700c9d4ed6a5e952213608706440c7eac
3
+ metadata.gz: b7cab0f2557ace7ed091eb02c7090a595d0cfb586313b9f03b4727172e9fd670
4
+ data.tar.gz: 5dcc6d2ee8e6d99612e6999549c944820b7485735947e80ee953498f2c5cf829
5
5
  SHA512:
6
- metadata.gz: fe19cf7af34c499bfd4d1811f8cc40d1e62e2f5df42f3ad47568e412864491aaa2dc709076ccfe5007509d9ffd9a94ba994e4cfbfc778eef52f89b6dc392c90f
7
- data.tar.gz: 4404dd0fe82faf3d813b3ff767a2d53219ea339dbd5f5e416f115f3b4a0cb4dacb3dff75885a093a5025aece1b3d5d17e8a77d3f1f4cf1d67e8e8e929dfb11e8
6
+ metadata.gz: 71561f7bf678621e8061be51fd5a833c47ac219eb7f7ba010f8a210ba45c108d3f389ab743b87ab4bbc9d6f6aba95bfbd1694bb6f6c9319fa6e17880cd9fa54f
7
+ data.tar.gz: 2c596c55ae278c66b5081a4d06aabfa43f83e8fd162675c2517299f120e231dd56f8d91a7fa0e7d1d7d0e7390022c825db71d5e71013b4d68b98b8daaf89ce86
data/README.md CHANGED
@@ -23,7 +23,19 @@ After loading your gems, tell `OTR::ActiveRecord` about your database config usi
23
23
  **Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
24
24
  This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.
25
25
 
26
- #### 3. Enable middleware for Rack apps
26
+ #### 3. Connect to your database(s)
27
+
28
+ If you have a single database (most apps), use this helper:
29
+
30
+ OTR::ActiveRecord.establish_connection!
31
+
32
+ If you're using multiple databases, call your base class(es) instead:
33
+
34
+ MyBase.establish_connection :primary
35
+ MyBase.establish_connection :primary_replica
36
+ ...
37
+
38
+ #### 4. Enable middleware for Rack apps
27
39
 
28
40
  Add these middlewares in `config.ru`:
29
41
 
@@ -33,7 +45,7 @@ Add these middlewares in `config.ru`:
33
45
  # Enable ActiveRecord's QueryCache for every request (optional)
34
46
  use OTR::ActiveRecord::QueryCache
35
47
 
36
- #### 4. Import ActiveRecord tasks into your Rakefile
48
+ #### 5. Import ActiveRecord tasks into your Rakefile
37
49
 
38
50
  This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
39
51
 
@@ -26,7 +26,6 @@ module OTR
26
26
  def self.configure_from_hash!(spec)
27
27
  config = spec.stringify_keys.merge("migrations_paths" => ::OTR::ActiveRecord.migrations_paths)
28
28
  ::ActiveRecord::Base.configurations = {rack_env.to_s => config}
29
- ::ActiveRecord::Base.establish_connection(rack_env)
30
29
  end
31
30
 
32
31
  # Connect to database with a DB URL. Example: "postgres://user:pass@localhost/db"
@@ -40,10 +39,20 @@ module OTR
40
39
  ::ActiveRecord::Base.configurations =
41
40
  (YAML.load(ERB.new(File.read(path)).result) || {}).
42
41
  reduce({}) { |a, (env, config)|
43
- a[env] = {"migrations_paths" => ::OTR::ActiveRecord.migrations_paths}.merge config
42
+ if config.has_key? "database"
43
+ a[env] = {"migrations_paths" => ::OTR::ActiveRecord.migrations_paths}.merge config
44
+ elsif env == rack_env.to_s
45
+ config.each do |dbname, subconfig|
46
+ a[dbname.to_sym] = {"migrations_paths" => ::OTR::ActiveRecord.migrations_paths}.merge subconfig
47
+ end
48
+ end
44
49
  a
45
50
  }
46
- ::ActiveRecord::Base.establish_connection(rack_env)
51
+ end
52
+
53
+ # Establish a connection to the given db (defaults to current rack env)
54
+ def self.establish_connection!(db = rack_env)
55
+ ::ActiveRecord::Base.establish_connection(db)
47
56
  end
48
57
 
49
58
  # The current Rack environment
@@ -1,6 +1,6 @@
1
1
  module OTR
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '1.4.2'
4
+ VERSION = '2.0.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: otr-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-03 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord