sinatra-activerecord 2.0.20 → 2.0.24

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: 536a528576f9a003de9a0f910ee935d5028e7ec10652bb5ca43bcd23e9cd5e25
4
- data.tar.gz: d08f1ee914093a0918d31be3435961e863b497b869326dd7e1d05de5480212ce
3
+ metadata.gz: 915ee68564f8c6e934250b72f2953da682a4f83093e6ec2faaa69c2f646fe753
4
+ data.tar.gz: e53038e87fd52df06156caf21fdfb3d9dc60ddf9de91abc3e79a5c431655237c
5
5
  SHA512:
6
- metadata.gz: f1c964a3b55958eafc132f9caa8b74f4b5a57905244ec13b7fcf1374a9887c062b6556480133d9d3a802b12e00da273a706c2945aeb533160e1fdbb09805ceff
7
- data.tar.gz: 5f13ff25c06d4c2bbb0136d266327d3b9a0da08e69bbf372e2a1798308999d2f90e00aa494a8597b93c9faa36079b466e98dd1ed9368e63cd0fe12950ba556ee
6
+ metadata.gz: ca0a40e61bded7ea250e26c44004e6ec22ca8849efa4a4349acc0ff8cc9d1364dfe6d9c36484a52a2c306fbe039dfc32321b0434c4afe78436b1958a74957e57
7
+ data.tar.gz: 9d3f855a19210f1e72b674f41c3d686b837bd722d1393a86a688752da00b493c49f7ad81e68f91ef8fcdb91e25163c307aaa4a7859c3b3f126f740ed9cd6e638
data/README.md CHANGED
@@ -35,6 +35,12 @@ 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
+
40
+
41
+ Note: If you are using ActiveRecord 6.0 and above, and have [defined multiple databases](https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application) for the database.yml, the $DATABASE_URL configuration will be discarded, following [Active Record convention here](https://github.com/rails/rails/blob/main/activerecord/lib/active_record/database_configurations.rb#L169).
42
+
43
+
38
44
  Note that in **modular** Sinatra applications you will need to first register
39
45
  the extension:
40
46
 
@@ -147,8 +153,9 @@ This gem was made in 2009 by Blake Mizerany, creator of Sinatra.
147
153
 
148
154
  ## Social
149
155
 
150
- You can follow me on Twitter, I'm [@jankomarohnic](http://twitter.com/jankomarohnic).
156
+ You can follow Janko on Twitter, [@jankomarohnic](http://twitter.com/jankomarohnic).
157
+ You can follow Axel on Twitter, [@soulchildpls](http://twitter.com/soulchildpls).
151
158
 
152
159
  ## License
153
160
 
154
- [MIT](https://github.com/janko-m/sinatra-activerecord/blob/master/LICENSE)
161
+ [MIT](https://github.com/sinatra-activerecord/sinatra-activerecord/blob/master/LICENSE)
@@ -7,6 +7,8 @@ require 'pathname'
7
7
  require 'yaml'
8
8
  require 'erb'
9
9
 
10
+ require 'active_record/database_configurations/connection_url_resolver' if Gem.loaded_specs["activerecord"].version >= Gem::Version.create('6.1')
11
+
10
12
  module Sinatra
11
13
  module ActiveRecordHelper
12
14
  def database
@@ -16,7 +18,36 @@ module Sinatra
16
18
 
17
19
  module ActiveRecordExtension
18
20
  def self.registered(app)
19
- if ENV['DATABASE_URL']
21
+ if ENV['DATABASE_URL'] && File.exist?("#{Dir.pwd}/config/database.yml")
22
+ path = "#{Dir.pwd}/config/database.yml"
23
+ url = ENV['DATABASE_URL']
24
+ file_path = File.join(root, path) if Pathname(path).relative? and root
25
+ source = ERB.new(File.read(path)).result
26
+ file_spec = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(source) : YAML.load(source)
27
+ file_spec ||= {}
28
+
29
+ # ActiveRecord 6.1+ has moved the connection url resolver to another module
30
+ if Gem.loaded_specs["activerecord"].version >= Gem::Version.create('6.1')
31
+ url_spec = ActiveRecord::DatabaseConfigurations::ConnectionUrlResolver.new(url).to_hash
32
+ else
33
+ url_spec = ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(url).to_hash
34
+ end
35
+
36
+ # if the configuration concerns only one database, and url_spec exist, url_spec will override the same key
37
+ # if the configuration has multiple databases (Rails 6.0+ feature), url_spec is discarded
38
+ # Following Active Record config convention
39
+ # https://github.com/rails/rails/blob/main/activerecord/lib/active_record/database_configurations.rb#L169
40
+ final_spec = file_spec.keys.map do |env|
41
+ config = file_spec[env]
42
+ if config.is_a?(Hash) && config.all? { |_k, v| v.is_a?(Hash) }
43
+ [env, config]
44
+ else
45
+ [env, config.merge(url_spec)]
46
+ end
47
+ end.to_h
48
+
49
+ app.set :database, final_spec
50
+ elsif ENV['DATABASE_URL']
20
51
  app.set :database, ENV['DATABASE_URL']
21
52
  elsif File.exist?("#{Dir.pwd}/config/database.yml")
22
53
  app.set :database_file, "#{Dir.pwd}/config/database.yml"
@@ -35,7 +66,9 @@ module Sinatra
35
66
 
36
67
  def database_file=(path)
37
68
  path = File.join(root, path) if Pathname(path).relative? and root
38
- spec = YAML.load(ERB.new(File.read(path)).result) || {}
69
+ source = ERB.new(File.read(path)).result
70
+ spec = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(source) : YAML.load(source)
71
+ spec ||= {}
39
72
  set :database, spec
40
73
  end
41
74
 
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.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
8
8
  - Janko Marohnić
9
- autorequire:
9
+ - Axel Kee
10
+ autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2020-10-23 00:00:00.000000000 Z
13
+ date: 2021-12-26 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,11 +111,11 @@ 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: {}
117
- post_install_message:
118
+ post_install_message:
118
119
  rdoc_options: []
119
120
  require_paths:
120
121
  - lib
@@ -129,8 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  - !ruby/object:Gem::Version
130
131
  version: '0'
131
132
  requirements: []
132
- rubygems_version: 3.1.2
133
- signing_key:
133
+ rubygems_version: 3.1.6
134
+ signing_key:
134
135
  specification_version: 4
135
136
  summary: Extends Sinatra with ActiveRecord helpers.
136
137
  test_files: []