cache_with_settings 1.0.1 → 1.1.0

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: 57ebed20eb0d765842ce7458b3c3132fa56e36ef83d8398420a214df29241ce6
4
- data.tar.gz: 35d0952e1a8fe83be020898ea874cd398675a8d497a6ffa03df1f13f5cb6ee03
3
+ metadata.gz: b76cecffa2413d7b9fef263126e442c308f5bceef78be1247625d9d389c89f71
4
+ data.tar.gz: 06da2bd8e0b1df6815ed1dbafd87ae78d0b7708c2112cb3b4570949b1278c2b0
5
5
  SHA512:
6
- metadata.gz: a203fd0b9e512b17cfddf6a78b9eb3ccccfd6c597cbd875d1b5e9af20fe00047a13f0daa893e5abe9425a6e80d93580fcaf7c891e92cddac8971f47bc8791258
7
- data.tar.gz: f923131cc36b7b7c69ee337fadd72b26b731e787d8d55ead36fa06e43ceecbe11ebaf47e47890fa67c8751e242460ce022de73681958c128e03c8b1d16a13e1c
6
+ metadata.gz: 91791e4f60deffc829bcfb4f734e38bd5f7b8051d21a3e541794291157f255f07245ced1ce07cbc9edeb9b9934e6fe45760d55e80d4a8047897089fd70d3945b
7
+ data.tar.gz: 77384b41454b3043ce8be3135172608aba5e14a68fb198aad6d1941689adae05f65ba13303d2e58bf0fe43b5f4875d57168c44d15952c41ba04bd1c7e3b01631
data/README.md CHANGED
@@ -33,6 +33,14 @@ end
33
33
 
34
34
  That's it! Your template `cache` calls now automatically include the specified cache keys.
35
35
 
36
+ Collection caching is also supported. If you're rendering collections with `cached: true` your specified cache keys will automatically be included:
37
+
38
+ ```erb
39
+ <%= render partial: "cities/city",
40
+ collection: @cities,
41
+ cached: true %>
42
+ ```
43
+
36
44
  ## Installation
37
45
  Add this line to your application's Gemfile:
38
46
 
@@ -1,19 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "cache_with_settings/configuration"
4
+ require "cache_with_settings/helpers/cache_helper"
5
+ require "cache_with_settings/helpers/rendering_helper"
4
6
  require "cache_with_settings/railtie"
5
7
 
6
8
  module CacheWithSettings
7
9
  module Helpers
8
- def cache(key, options = {}, &block)
9
- super(cache_with_settings_compose_key(key), options) do
10
- yield(block)
11
- end
12
- end
10
+ end
13
11
 
14
- private
15
- def cache_with_settings_compose_key(key)
16
- Array.wrap(key).concat(CacheWithSettings.cache_keys.call)
17
- end
12
+ def self.compose_key(key)
13
+ Array.wrap(key).concat(CacheWithSettings.cache_keys.call)
18
14
  end
19
15
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CacheWithSettings::Helpers
4
+ module CacheHelper
5
+ def cache(key, options = {}, &block)
6
+ super(CacheWithSettings.compose_key(key), options) do
7
+ yield(block)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CacheWithSettings::Helpers
4
+ module RenderingHelper
5
+ def render(options = {}, locals = {}, &block)
6
+ if options.kind_of?(Hash) && options[:cached] == true
7
+ options[:cached] = -> object { CacheWithSettings.compose_key(object) }
8
+ end
9
+
10
+ if block_given?
11
+ super(options, locals) { yield(block) }
12
+ else
13
+ super(options, locals)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -2,9 +2,10 @@
2
2
 
3
3
  module CacheWithSettings
4
4
  class Railtie < ::Rails::Railtie
5
- initializer "rails_db.helpers" do
5
+ initializer "cache_with_settings.helpers" do
6
6
  ActiveSupport.on_load :action_view do
7
- ActionView::Base.send :include, CacheWithSettings::Helpers
7
+ ActionView::Base.send :include, CacheWithSettings::Helpers::CacheHelper
8
+ ActionView::Base.send :include, CacheWithSettings::Helpers::RenderingHelper
8
9
  end
9
10
  end
10
11
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CacheWithSettings
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cache_with_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Venneman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-09 00:00:00.000000000 Z
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -79,6 +79,8 @@ files:
79
79
  - Rakefile
80
80
  - lib/cache_with_settings.rb
81
81
  - lib/cache_with_settings/configuration.rb
82
+ - lib/cache_with_settings/helpers/cache_helper.rb
83
+ - lib/cache_with_settings/helpers/rendering_helper.rb
82
84
  - lib/cache_with_settings/railtie.rb
83
85
  - lib/cache_with_settings/version.rb
84
86
  - lib/tasks/cache_with_settings_tasks.rake