multi_fetch_fragments 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/multi_fetch_fragments.rb +10 -3
  2. metadata +3 -3
@@ -18,7 +18,7 @@ module MultiFetchFragments
18
18
 
19
19
  if cache_collection?
20
20
 
21
- additional_cache_options = @options.fetch(:cache_options, {})
21
+ additional_cache_options = @options[:cache_options] || @locals[:cache_options] || {}
22
22
  keys_to_collection_map = {}
23
23
 
24
24
  @collection.each do |item|
@@ -33,7 +33,8 @@ module MultiFetchFragments
33
33
  key_with_optional_digest = key
34
34
  end
35
35
 
36
- expanded_key = @view.controller.fragment_cache_key(key_with_optional_digest)
36
+
37
+ expanded_key = fragment_cache_key(key_with_optional_digest)
37
38
 
38
39
  keys_to_collection_map[expanded_key] = item
39
40
  end
@@ -41,7 +42,7 @@ module MultiFetchFragments
41
42
  # cache.read_multi & cache.write interfaces may require mutable keys, ie. dalli 2.6.0
42
43
  mutable_keys = keys_to_collection_map.keys.collect { |key| key.dup }
43
44
 
44
- result_hash = Rails.cache.read_multi(mutable_keys)
45
+ result_hash = Rails.cache.read_multi(*mutable_keys)
45
46
 
46
47
  # if we had a cached value, we don't need to render that object from the collection.
47
48
  # if it wasn't cached, we need to render those objects as before
@@ -82,6 +83,12 @@ module MultiFetchFragments
82
83
  ActionController::Base.perform_caching && cache_option
83
84
  end
84
85
 
86
+ # from Rails fragment_cache_key in ActionController::Caching::Fragments. Adding it here since it's tucked inside an instance method on the controller, and
87
+ # it's utility could be used in a view without a controller
88
+ def fragment_cache_key(key)
89
+ ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
90
+ end
91
+
85
92
  class Railtie < Rails::Railtie
86
93
  initializer "multi_fetch_fragments.initialize" do |app|
87
94
  ActionView::PartialRenderer.class_eval do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_fetch_fragments
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-07-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec-rails
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project:
57
- rubygems_version: 1.8.24
57
+ rubygems_version: 1.8.23
58
58
  signing_key:
59
59
  specification_version: 3
60
60
  summary: multi_fetch_fragments allows you to render a collection of partials through