otr-activerecord 1.2.7 → 1.4.2

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: 2673ab10a9f4bfe00341e5f5fdfc88642417763fcaf703bd431df1c81663364d
4
- data.tar.gz: 4fb5873b1e6057f59d328c1a4b75bc62c3ee702521faa06878dda45899934be4
3
+ metadata.gz: c8dad01fcadb48149aac6d50f0e66507bab5bb35bfa42af74d5c4f35a6706ef4
4
+ data.tar.gz: 2abf82a804042bfb986cef869c7be5f700c9d4ed6a5e952213608706440c7eac
5
5
  SHA512:
6
- metadata.gz: 328ec2d96e3e13c816ec8b31536a8b8d558c25b7ca365af686bd9cd9c0c4b272fdda72ae23423a5446e8e74b387a4a45afc4e16e80f99d6d0ec6009f444b3a37
7
- data.tar.gz: 28ff18f109772d656403cc9f9b6b399fbbcf7cabffec6e9ddfb06895aa4401c25ecc9ef3e7e63a584b42c1e0348e4b86a1e0fb7c1993d02355e26a3660128b53
6
+ metadata.gz: fe19cf7af34c499bfd4d1811f8cc40d1e62e2f5df42f3ad47568e412864491aaa2dc709076ccfe5007509d9ffd9a94ba994e4cfbfc778eef52f89b6dc392c90f
7
+ data.tar.gz: 4404dd0fe82faf3d813b3ff767a2d53219ea339dbd5f5e416f115f3b4a0cb4dacb3dff75885a093a5025aece1b3d5d17e8a77d3f1f4cf1d67e8e8e929dfb11e8
data/README.md CHANGED
@@ -2,8 +2,9 @@
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 4
5
+ * ActiveRecord 6
6
6
  * ActiveRecord 5
7
+ * ActiveRecord 4
7
8
 
8
9
  ## How to use
9
10
 
@@ -22,12 +23,16 @@ After loading your gems, tell `OTR::ActiveRecord` about your database config usi
22
23
  **Important note**: `configure_from_file!` won't work as expected if you have already `DATABASE_URL` set as part of your environment variables.
23
24
  This is because in ActiveRecord when that env variable is set it will merge its properties into the current connection configuration.
24
25
 
25
- #### 3. Enable ActiveRecord connection management in Rack apps
26
+ #### 3. Enable middleware for Rack apps
26
27
 
27
- This middleware cleans up your database connections after each request. Add it to your `config.ru` file:
28
+ Add these middlewares in `config.ru`:
28
29
 
30
+ # Clean up database connections after every request (required)
29
31
  use OTR::ActiveRecord::ConnectionManagement
30
32
 
33
+ # Enable ActiveRecord's QueryCache for every request (optional)
34
+ use OTR::ActiveRecord::QueryCache
35
+
31
36
  #### 4. Import ActiveRecord tasks into your Rakefile
32
37
 
33
38
  This will give you most of the standard `db:` tasks you get in Rails. Add it to your `Rakefile`.
@@ -2,5 +2,6 @@ require 'active_record'
2
2
  require 'hashie-forbidden_attributes'
3
3
  require 'otr-activerecord/version'
4
4
  require 'otr-activerecord/activerecord'
5
- require 'otr-activerecord/middleware/connection_management.rb'
5
+ require 'otr-activerecord/middleware/connection_management'
6
+ require 'otr-activerecord/middleware/query_cache'
6
7
  require 'otr-activerecord/defaults'
@@ -6,6 +6,7 @@ module OTR
6
6
  module ActiveRecord
7
7
  autoload :Compatibility4, 'otr-activerecord/compatibility_4'
8
8
  autoload :Compatibility5, 'otr-activerecord/compatibility_5'
9
+ autoload :Compatibility6, 'otr-activerecord/compatibility_6'
9
10
 
10
11
  class << self
11
12
  # Relative path to the "db" dir
@@ -0,0 +1,36 @@
1
+ module OTR
2
+ module ActiveRecord
3
+ # Compatibility layer for ActiveRecord 6
4
+ class Compatibility6
5
+ attr_reader :major_version
6
+
7
+ # Compatibility layer for ActiveRecord 6
8
+ def initialize
9
+ @major_version = 6
10
+ ::ActiveRecord::Base.default_timezone = :utc
11
+ ::ActiveRecord::Base.logger = Logger.new(STDOUT)
12
+ end
13
+
14
+ # All db migration dir paths
15
+ def migrations_paths
16
+ OTR::ActiveRecord.migrations_paths
17
+ end
18
+
19
+ # The dir in which to put new migrations
20
+ def migrations_path
21
+ OTR::ActiveRecord.migrations_paths[0]
22
+ end
23
+
24
+ # Basename of migration classes
25
+ def migration_base_class_name
26
+ version = "6.#{::ActiveRecord::VERSION::MINOR}"
27
+ "ActiveRecord::Migration[#{version}]"
28
+ end
29
+
30
+ # Force RACK_ENV/RAILS_ENV to be 'test' when running any db:test:* tasks
31
+ def force_db_test_env?
32
+ false
33
+ end
34
+ end
35
+ end
36
+ end
@@ -7,4 +7,5 @@ OTR::ActiveRecord.seed_file = 'seeds.rb'
7
7
  OTR::ActiveRecord._normalizer = case ::ActiveRecord::VERSION::MAJOR
8
8
  when 4 then OTR::ActiveRecord::Compatibility4.new
9
9
  when 5 then OTR::ActiveRecord::Compatibility5.new
10
+ when 6 then OTR::ActiveRecord::Compatibility6.new
10
11
  end
@@ -0,0 +1,33 @@
1
+ module OTR
2
+ module ActiveRecord
3
+ #
4
+ # Rack middleware to enable ActiveRecord's query cache for each request.
5
+ #
6
+ class QueryCache
7
+ def initialize(app)
8
+ @handler = case ::ActiveRecord::VERSION::MAJOR
9
+ when 4 then ::ActiveRecord::QueryCache.new(app)
10
+ when 5, 6 then ActionDispatchHandler.new(app)
11
+ end
12
+ end
13
+
14
+ def call(env)
15
+ @handler.call(env)
16
+ end
17
+
18
+ class ActionDispatchHandler
19
+ def initialize(app)
20
+ @app = app
21
+ end
22
+
23
+ def call(env)
24
+ state = nil
25
+ state = ::ActiveRecord::QueryCache.run
26
+ @app.call(env)
27
+ ensure
28
+ ::ActiveRecord::QueryCache.complete(state) if state
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -1,6 +1,6 @@
1
1
  module OTR
2
2
  module ActiveRecord
3
3
  # Gem version
4
- VERSION = '1.2.7'
4
+ VERSION = '1.4.2'
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.2.7
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
11
+ date: 2020-04-03 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: '5.3'
22
+ version: '6.3'
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: '5.3'
32
+ version: '6.3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: hashie-forbidden_attributes
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -57,8 +57,10 @@ files:
57
57
  - lib/otr-activerecord/activerecord.rb
58
58
  - lib/otr-activerecord/compatibility_4.rb
59
59
  - lib/otr-activerecord/compatibility_5.rb
60
+ - lib/otr-activerecord/compatibility_6.rb
60
61
  - lib/otr-activerecord/defaults.rb
61
62
  - lib/otr-activerecord/middleware/connection_management.rb
63
+ - lib/otr-activerecord/middleware/query_cache.rb
62
64
  - lib/otr-activerecord/version.rb
63
65
  - lib/tasks/otr-activerecord.rake
64
66
  homepage: https://github.com/jhollinger/otr-activerecord
@@ -80,8 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
82
  - !ruby/object:Gem::Version
81
83
  version: '0'
82
84
  requirements: []
83
- rubyforge_project:
84
- rubygems_version: 2.7.6
85
+ rubygems_version: 3.0.3
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: 'Off The Rails: Use ActiveRecord with Grape, Sinatra, Rack, or anything else!'