sinatra-activerecord 2.0.21 → 2.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/sinatra/activerecord/rake/activerecord_7.rb +23 -0
- data/lib/sinatra/activerecord.rb +27 -6
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbf1bdfb5b4d0cd2e37a4ede129988d22bfbeb3735db2286208212f67ef95443
|
4
|
+
data.tar.gz: f2acbe1309ee18f23fe201584be53e499306246a7e676c5fa84ec3a2cb14d395
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5671059aac55202a024f58c1f96ecc7b10f371a513d80031e8542cc9c41be5bddf191b365529db191523a438aeccbbb149902e9811e28d46b5abb7ea14e9612d
|
7
|
+
data.tar.gz: 7fa63a69a728758271a9f82a50cdeb0cd6d382258fef5784521018ff6c1db7813f5064692b0229b5771d8f88c2804bfca54c8c57df2cfe64a18f26a3e2d66932
|
data/README.md
CHANGED
@@ -37,6 +37,10 @@ will automatically be read as the database (if you haven't specified otherwise).
|
|
37
37
|
|
38
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
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
|
+
|
40
44
|
Note that in **modular** Sinatra applications you will need to first register
|
41
45
|
the extension:
|
42
46
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
seed_loader = Class.new do
|
2
|
+
def load_seed
|
3
|
+
load "#{ActiveRecord::Tasks::DatabaseTasks.db_dir}/seeds.rb"
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
ActiveRecord::Tasks::DatabaseTasks.tap do |config|
|
8
|
+
config.root = Rake.application.original_dir
|
9
|
+
config.env = ENV["APP_ENV"] || ENV["RACK_ENV"] || "development"
|
10
|
+
config.db_dir = "db"
|
11
|
+
config.migrations_paths = ["db/migrate"]
|
12
|
+
config.fixtures_path = "test/fixtures"
|
13
|
+
config.seed_loader = seed_loader.new
|
14
|
+
config.database_configuration = ActiveRecord::Base.configurations
|
15
|
+
end
|
16
|
+
|
17
|
+
# db:load_config can be overriden manually
|
18
|
+
Rake::Task["db:seed"].enhance(["db:load_config"])
|
19
|
+
Rake::Task["db:load_config"].clear
|
20
|
+
|
21
|
+
# define Rails' tasks as no-op
|
22
|
+
Rake::Task.define_task("db:environment")
|
23
|
+
Rake::Task["db:test:deprecated"].clear if Rake::Task.task_defined?("db:test:deprecated")
|
data/lib/sinatra/activerecord.rb
CHANGED
@@ -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
|
@@ -20,12 +22,29 @@ module Sinatra
|
|
20
22
|
path = "#{Dir.pwd}/config/database.yml"
|
21
23
|
url = ENV['DATABASE_URL']
|
22
24
|
file_path = File.join(root, path) if Pathname(path).relative? and root
|
23
|
-
|
24
|
-
|
25
|
-
|
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 ||= {}
|
26
28
|
|
27
|
-
#
|
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
|
29
48
|
|
30
49
|
app.set :database, final_spec
|
31
50
|
elsif ENV['DATABASE_URL']
|
@@ -47,7 +66,9 @@ module Sinatra
|
|
47
66
|
|
48
67
|
def database_file=(path)
|
49
68
|
path = File.join(root, path) if Pathname(path).relative? and root
|
50
|
-
|
69
|
+
source = ERB.new(File.read(path)).result
|
70
|
+
spec = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(source) : YAML.load(source)
|
71
|
+
spec ||= {}
|
51
72
|
set :database, spec
|
52
73
|
end
|
53
74
|
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Mizerany
|
8
8
|
- Janko Marohnić
|
9
9
|
- Axel Kee
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2021-12-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sinatra
|
@@ -110,12 +110,13 @@ files:
|
|
110
110
|
- lib/sinatra/activerecord/rake/activerecord_4.rb
|
111
111
|
- lib/sinatra/activerecord/rake/activerecord_5.rb
|
112
112
|
- lib/sinatra/activerecord/rake/activerecord_6.rb
|
113
|
+
- lib/sinatra/activerecord/rake/activerecord_7.rb
|
113
114
|
- lib/sinatra/activerecord/tasks.rake
|
114
115
|
homepage: http://github.com/sinatra-activerecord/sinatra-activerecord
|
115
116
|
licenses:
|
116
117
|
- MIT
|
117
118
|
metadata: {}
|
118
|
-
post_install_message:
|
119
|
+
post_install_message:
|
119
120
|
rdoc_options: []
|
120
121
|
require_paths:
|
121
122
|
- lib
|
@@ -130,8 +131,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
131
|
- !ruby/object:Gem::Version
|
131
132
|
version: '0'
|
132
133
|
requirements: []
|
133
|
-
rubygems_version: 3.1.
|
134
|
-
signing_key:
|
134
|
+
rubygems_version: 3.1.6
|
135
|
+
signing_key:
|
135
136
|
specification_version: 4
|
136
137
|
summary: Extends Sinatra with ActiveRecord helpers.
|
137
138
|
test_files: []
|