otr-activerecord 2.0.0 → 2.0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e566ff7225406da58fdb74cf202e283bacf60486ab841aa45be19607efc54d
|
4
|
+
data.tar.gz: 3ee87d6850730d55c0aa64c71b5b68a17f3ab784f568377a164ea63df6b6ff3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5fb891ef5c65446dd662e89b401b77354257e571513d8ae9d9657a55fd24b3f4838d0d86e863d492537f8c5ea7f57ee97f6beaa3c5c6a9962af22e947af80ae
|
7
|
+
data.tar.gz: cbe9dc7f8ab23c2d475efd33915be5ff4f64b8672a6aba424d350b5bc1cf5d811af15955c6777acb4406b1b0e1aa73151bbf43432e7a54a149a4e7148aa6ce7f
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
An easy way to use ActiveRecord "off the rails." Works with Grape, Sinatra, plain old Rack, or even in a boring little script!. The defaults are all very Railsy (`config/database.yml`, `db/seeds.rb`, `db/migrate`, etc.), but you can easily change them. (Formerly known as `grape-activerecord`.) Supports:
|
4
4
|
|
5
|
+
* ActiveRecord 7.0.0.alpha2 (new AR features, like encryption, not tested)
|
5
6
|
* ActiveRecord 6
|
6
7
|
* ActiveRecord 5
|
7
8
|
* ActiveRecord 4
|
@@ -7,6 +7,7 @@ module OTR
|
|
7
7
|
autoload :Compatibility4, 'otr-activerecord/compatibility_4'
|
8
8
|
autoload :Compatibility5, 'otr-activerecord/compatibility_5'
|
9
9
|
autoload :Compatibility6, 'otr-activerecord/compatibility_6'
|
10
|
+
autoload :Compatibility7, 'otr-activerecord/compatibility_7'
|
10
11
|
|
11
12
|
class << self
|
12
13
|
# Relative path to the "db" dir
|
@@ -30,24 +31,43 @@ module OTR
|
|
30
31
|
|
31
32
|
# Connect to database with a DB URL. Example: "postgres://user:pass@localhost/db"
|
32
33
|
def self.configure_from_url!(url)
|
33
|
-
|
34
|
+
require 'uri'
|
35
|
+
uri = URI(url)
|
36
|
+
spec = {"adapter" => uri.scheme}
|
37
|
+
|
38
|
+
case spec["adapter"]
|
39
|
+
when /^sqlite/i
|
40
|
+
spec["database"] = url =~ /::memory:/ ? ":memory:" : "#{uri.host}#{uri.path}"
|
41
|
+
else
|
42
|
+
spec["host"] = uri.host if uri.host
|
43
|
+
spec["port"] = uri.port if uri.port
|
44
|
+
spec["database"] = uri.path.sub(/^\//, "")
|
45
|
+
spec["username"] = uri.user if uri.user
|
46
|
+
spec["password"] = uri.password if uri.password
|
47
|
+
end
|
48
|
+
|
49
|
+
if uri.query
|
50
|
+
opts_ary = URI.decode_www_form(uri.query)
|
51
|
+
opts = Hash[opts_ary]
|
52
|
+
spec.merge!(opts)
|
53
|
+
end
|
54
|
+
|
55
|
+
configure_from_hash! spec
|
34
56
|
end
|
35
57
|
|
36
58
|
# Connect to database with a yml file. Example: "config/database.yml"
|
37
59
|
def self.configure_from_file!(path)
|
38
60
|
raise "#{path} does not exist!" unless File.file? path
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
if config.
|
43
|
-
|
44
|
-
|
45
|
-
config
|
46
|
-
a[dbname.to_sym] = {"migrations_paths" => ::OTR::ActiveRecord.migrations_paths}.merge subconfig
|
47
|
-
end
|
61
|
+
result = load_yaml(path)
|
62
|
+
::ActiveRecord::Base.configurations = begin
|
63
|
+
result.each do |_env, config|
|
64
|
+
if config.all? { |_, v| v.is_a?(Hash) }
|
65
|
+
config.each { |_, v| append_migration_path(v) }
|
66
|
+
else
|
67
|
+
append_migration_path(config)
|
48
68
|
end
|
49
|
-
|
50
|
-
|
69
|
+
end
|
70
|
+
end
|
51
71
|
end
|
52
72
|
|
53
73
|
# Establish a connection to the given db (defaults to current rack env)
|
@@ -55,9 +75,29 @@ module OTR
|
|
55
75
|
::ActiveRecord::Base.establish_connection(db)
|
56
76
|
end
|
57
77
|
|
78
|
+
def self.append_migration_path(config)
|
79
|
+
config['migrations_paths'] = ::OTR::ActiveRecord.migrations_paths unless config.key?('migrations_paths')
|
80
|
+
config
|
81
|
+
end
|
82
|
+
|
58
83
|
# The current Rack environment
|
59
84
|
def self.rack_env
|
60
85
|
(ENV['RACK_ENV'] || ENV['RAILS_ENV'] || ENV['APP_ENV'] || ENV['OTR_ENV'] || 'development').to_sym
|
61
86
|
end
|
87
|
+
|
88
|
+
# Support old Psych versions
|
89
|
+
def self.load_yaml(path)
|
90
|
+
erb_result = ERB.new(File.read(path)).result
|
91
|
+
|
92
|
+
result = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1')
|
93
|
+
YAML.safe_load(erb_result, aliases: true)
|
94
|
+
else
|
95
|
+
YAML.safe_load(erb_result, [], [], true)
|
96
|
+
end
|
97
|
+
|
98
|
+
result || {}
|
99
|
+
end
|
100
|
+
|
101
|
+
private_class_method :load_yaml
|
62
102
|
end
|
63
103
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module OTR
|
2
|
+
module ActiveRecord
|
3
|
+
# Compatibility layer for ActiveRecord 7
|
4
|
+
class Compatibility7 < Compatibility6
|
5
|
+
def initialize
|
6
|
+
@major_version = 7
|
7
|
+
::ActiveRecord.default_timezone = :utc
|
8
|
+
::ActiveRecord::Base.logger = Logger.new(STDOUT)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -4,8 +4,10 @@ OTR::ActiveRecord.db_dir = 'db'
|
|
4
4
|
OTR::ActiveRecord.migrations_paths = %w(db/migrate)
|
5
5
|
OTR::ActiveRecord.fixtures_path = 'test/fixtures'
|
6
6
|
OTR::ActiveRecord.seed_file = 'seeds.rb'
|
7
|
-
OTR::ActiveRecord._normalizer =
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
OTR::ActiveRecord._normalizer =
|
8
|
+
case ::ActiveRecord::VERSION::MAJOR
|
9
|
+
when 4 then OTR::ActiveRecord::Compatibility4.new
|
10
|
+
when 5 then OTR::ActiveRecord::Compatibility5.new
|
11
|
+
when 6 then OTR::ActiveRecord::Compatibility6.new
|
12
|
+
when 7 then OTR::ActiveRecord::Compatibility7.new
|
13
|
+
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: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordan Hollinger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '7.1'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '7.1'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: hashie-forbidden_attributes
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/otr-activerecord/compatibility_4.rb
|
59
59
|
- lib/otr-activerecord/compatibility_5.rb
|
60
60
|
- lib/otr-activerecord/compatibility_6.rb
|
61
|
+
- lib/otr-activerecord/compatibility_7.rb
|
61
62
|
- lib/otr-activerecord/defaults.rb
|
62
63
|
- lib/otr-activerecord/middleware/connection_management.rb
|
63
64
|
- lib/otr-activerecord/middleware/query_cache.rb
|
@@ -82,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
83
|
- !ruby/object:Gem::Version
|
83
84
|
version: '0'
|
84
85
|
requirements: []
|
85
|
-
rubygems_version: 3.0.3
|
86
|
+
rubygems_version: 3.0.3.1
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: 'Off The Rails: Use ActiveRecord with Grape, Sinatra, Rack, or anything else!'
|