sinatra-activerecord 2.0.20 → 2.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 536a528576f9a003de9a0f910ee935d5028e7ec10652bb5ca43bcd23e9cd5e25
4
- data.tar.gz: d08f1ee914093a0918d31be3435961e863b497b869326dd7e1d05de5480212ce
3
+ metadata.gz: 9b662752481c4940600cb421378b4dd447e549ea11a876c86a36d250f473e706
4
+ data.tar.gz: ac0a9176f4e2b0abd115664db78ba1bfeb7ed043dd190c3ed5251a794555a360
5
5
  SHA512:
6
- metadata.gz: f1c964a3b55958eafc132f9caa8b74f4b5a57905244ec13b7fcf1374a9887c062b6556480133d9d3a802b12e00da273a706c2945aeb533160e1fdbb09805ceff
7
- data.tar.gz: 5f13ff25c06d4c2bbb0136d266327d3b9a0da08e69bbf372e2a1798308999d2f90e00aa494a8597b93c9faa36079b466e98dd1ed9368e63cd0fe12950ba556ee
6
+ metadata.gz: 6b6bb226f78cc9fd45e928625b3c062077101fb0e8a9f58ad47fd8f374ab316e96cee7366872346c02bfb411306e997a8a2848b433b8103abba9643f2f8f2f48
7
+ data.tar.gz: 7c2b8cd35e0dc75e9ac1045c8a1074cdaa75eedadc6ce607fd8e99a30ba6f3b3e0abae2f0bfeab8276a38c840da529dc9f1cb5d689108c191cd29a36332958ce
data/README.md CHANGED
@@ -35,6 +35,8 @@ If you have a `config/database.yml`, it will automatically be loaded, no need
35
35
  to specify it. Also, in production, the `$DATABASE_URL` environment variable
36
36
  will automatically be read as the database (if you haven't specified otherwise).
37
37
 
38
+ If both `config/database.yml` and `$DATABASE_URL` are present, the database configuration of this two will be merged, with $DATABASE_URL's variable taking precedence over database.yml (for the same variable / key).
39
+
38
40
  Note that in **modular** Sinatra applications you will need to first register
39
41
  the extension:
40
42
 
@@ -147,8 +149,9 @@ This gem was made in 2009 by Blake Mizerany, creator of Sinatra.
147
149
 
148
150
  ## Social
149
151
 
150
- You can follow me on Twitter, I'm [@jankomarohnic](http://twitter.com/jankomarohnic).
152
+ You can follow Janko on Twitter, [@jankomarohnic](http://twitter.com/jankomarohnic).
153
+ You can follow Axel on Twitter, [@soulchildpls](http://twitter.com/soulchildpls).
151
154
 
152
155
  ## License
153
156
 
154
- [MIT](https://github.com/janko-m/sinatra-activerecord/blob/master/LICENSE)
157
+ [MIT](https://github.com/sinatra-activerecord/sinatra-activerecord/blob/master/LICENSE)
@@ -16,7 +16,19 @@ module Sinatra
16
16
 
17
17
  module ActiveRecordExtension
18
18
  def self.registered(app)
19
- if ENV['DATABASE_URL']
19
+ if ENV['DATABASE_URL'] && File.exist?("#{Dir.pwd}/config/database.yml")
20
+ path = "#{Dir.pwd}/config/database.yml"
21
+ url = ENV['DATABASE_URL']
22
+ file_path = File.join(root, path) if Pathname(path).relative? and root
23
+ file_spec = YAML.load(ERB.new(File.read(path)).result) || {}
24
+
25
+ url_spec = ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(url).to_hash
26
+
27
+ # url_spec will override the same key, if exist
28
+ final_spec = file_spec.keys.map{ |env| [env, file_spec[env].merge(url_spec)] }.to_h
29
+
30
+ app.set :database, final_spec
31
+ elsif ENV['DATABASE_URL']
20
32
  app.set :database, ENV['DATABASE_URL']
21
33
  elsif File.exist?("#{Dir.pwd}/config/database.yml")
22
34
  app.set :database_file, "#{Dir.pwd}/config/database.yml"
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.20
4
+ version: 2.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
8
8
  - Janko Marohnić
9
+ - Axel Kee
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2020-10-23 00:00:00.000000000 Z
13
+ date: 2020-10-24 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: sinatra
@@ -96,7 +97,7 @@ dependencies:
96
97
  - !ruby/object:Gem::Version
97
98
  version: '0'
98
99
  description: Extends Sinatra with ActiveRecord helpers.
99
- email: janko.marohnic@gmail.com
100
+ email: axel@rubyyagi.com
100
101
  executables: []
101
102
  extensions: []
102
103
  extra_rdoc_files: []
@@ -110,7 +111,7 @@ files:
110
111
  - lib/sinatra/activerecord/rake/activerecord_5.rb
111
112
  - lib/sinatra/activerecord/rake/activerecord_6.rb
112
113
  - lib/sinatra/activerecord/tasks.rake
113
- homepage: http://github.com/janko-m/sinatra-activerecord
114
+ homepage: http://github.com/sinatra-activerecord/sinatra-activerecord
114
115
  licenses:
115
116
  - MIT
116
117
  metadata: {}