active_record_multiple_query_cache 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 00050eb28914caff20e2c4a00c6597a734effcf1
4
- data.tar.gz: f7ccb81d7ab5034ee4d270c1eb1fca9162aa7271
3
+ metadata.gz: d2c39557d189b8d85b4e35ee4ae6f356d862cdfc
4
+ data.tar.gz: 7b46a465aa2b57d19e007cdca200c57c3a59880d
5
5
  SHA512:
6
- metadata.gz: 85d1785a38917b157d5d94bda59446cab464750ca4f9fb818a47d0fe20bf6ed8ec3337c390aafc8582b459458a9b78aaf50948e1aa72b77f0e2990a7014c09f5
7
- data.tar.gz: 4b64956e9d7995e7208625a257c645d1eb135d6cd333bc0b17cc9ca937b1faa2e6d21143975d3aa81d58753138a0ac8e3a4f720501a98262eedcd4abd8125634
6
+ metadata.gz: 897508b3089e9ff1a6f7cc7b99203df4de7db7e6fc1ef1100cb7e6c5928ec03fe27fcfa9d28d5be27adac0ffcb510db758fe4fdf9795c6bfdffb01e950f76286
7
+ data.tar.gz: cd1d2b0bb823a05e477077a14c5687dbbd74116621a94b2afe594074eebef80b47bba5453bb23895567a6f1806e13e43e5af73ef1af696f5dc312364f45bb725
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "activerecord_multiple_query_cache"
3
+ require 'bundler/setup'
4
+ require 'active_record_multiple_query_cache'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "activerecord_multiple_query_cache"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -1,13 +1,11 @@
1
1
  module ActiveRecordMultipleQueryCache
2
2
  class Rails5QueryCache
3
- def initialize(active_record_base_class)
4
- activerecord_base_class = active_record_base_class.constantize if active_record_base_class.is_a?(String)
5
-
6
- @active_record_base_class = active_record_base_class
3
+ def initialize(active_record_base_name_or_class)
4
+ @active_record_base_name_or_class = active_record_base_name_or_class
7
5
  end
8
6
 
9
7
  def run
10
- caching_pool = @active_record_base_class.connection_pool
8
+ caching_pool = active_record_base_class.connection.pool
11
9
  caching_was_enabled = caching_pool.query_cache_enabled
12
10
 
13
11
  caching_pool.enable_query_cache!
@@ -18,5 +16,15 @@ module ActiveRecordMultipleQueryCache
18
16
  def complete((caching_pool, caching_was_enabled))
19
17
  caching_pool.disable_query_cache! unless caching_was_enabled
20
18
  end
19
+
20
+ private
21
+
22
+ def active_record_base_class
23
+ @active_record_base_class ||= if @active_record_base_name_or_class.is_a?(String)
24
+ @active_record_base_name_or_class.constantize
25
+ else
26
+ @active_record_base_name_or_class
27
+ end
28
+ end
21
29
  end
22
30
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordMultipleQueryCache
2
- VERSION = "0.1.0"
2
+ VERSION = '0.1.1'.freeze
3
3
  end
@@ -5,14 +5,14 @@ module ActiveRecordMultipleQueryCache
5
5
  autoload :Rails4QueryCache, 'active_record_multiple_query_cache/rails4_query_cache'
6
6
  autoload :Rails5QueryCache, 'active_record_multiple_query_cache/rails5_query_cache'
7
7
 
8
- def self.install_query_cache(activerecord_base_class_name, rails = Rails)
8
+ def self.install_query_cache(activerecord_base_class_name, rails = ::Rails)
9
9
  if rails.gem_version >= Gem::Version.new('5.0.0')
10
10
  executor = ActiveSupport::Executor
11
- query_cache = Rails5QueryCache.new(activerecord_base_class_name)
11
+ hook = Rails5QueryCache.new(activerecord_base_class_name)
12
12
 
13
13
  executor.register_hook(hook)
14
14
  else
15
- middleware = ActiveRecordMultipleQueryCache::Rails4QueryCache.new(activerecord_base_class_name)
15
+ middleware = Rails4QueryCache.new(activerecord_base_class_name)
16
16
  rails.configuration.app_middleware.insert_after('::ActionDispatch::Callbacks', middleware)
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_multiple_query_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc