cache_with_settings 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +16 -14
- data/Rakefile +14 -12
- data/lib/cache_with_settings/configuration.rb +10 -0
- data/lib/cache_with_settings/railtie.rb +3 -1
- data/lib/cache_with_settings/version.rb +3 -1
- data/lib/cache_with_settings.rb +6 -4
- data/lib/tasks/cache_with_settings_tasks.rake +2 -0
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0afd8964a34b654ac33eb73501f28bff8e170667452b409749e48902bca8e7a
|
4
|
+
data.tar.gz: 3adbf5daaad4d0c8213205aab8b6ec24c38c1f123df18b64707b8429816709b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12e521466bbbe4494339c7e79ebebee5b3ba40d3e568f60bc56eb0116e69adc5ad703f81d9974e7873c23fec05c38f8bdf71404405ffdc58e932a9ec3cb7a542
|
7
|
+
data.tar.gz: bbfcbac8a8dde1644024bf5353ed6d618574a23baad684a8c7cc1dfd23592ba110d94e1288effecc7f0141db6dbd610f35642c6e73c71eeec18e4fd4ba9d932e
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,33 +1,35 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/richardvenneman/cache_with_settings.svg?branch=master)](https://travis-ci.org/richardvenneman/cache_with_settings)
|
2
2
|
|
3
|
-
# Rails
|
4
|
-
|
3
|
+
# Rails cache_with_settings
|
4
|
+
CacheWithSettings allows you to add any keys to partial caching cache keys. This is useful if your website is multilingual or allows the user to choose a display currency.
|
5
5
|
|
6
6
|
## Problem & Solution
|
7
|
-
|
8
|
-
- Rails app with different locales and currencies
|
9
|
-
- you want to add fragment caching in views
|
10
|
-
|
11
|
-
When you add locales and currencies to your cache keys:
|
7
|
+
If you find yourself adding dynamic values, such as locales and currencies to your cache keys, this gem could be useful for you. Instead of:
|
12
8
|
|
13
9
|
```
|
14
10
|
= cache [@user, I18n.locale, MoneyRails.default_currency] do
|
15
11
|
= render @user
|
16
12
|
```
|
17
13
|
|
18
|
-
|
19
|
-
|
20
|
-
This gem is a simple solution which allows you to DRY your code. So now you can write
|
14
|
+
Configure this gem once and just write:
|
21
15
|
|
22
16
|
```
|
23
17
|
= cache @user do
|
24
18
|
= render @user
|
25
19
|
```
|
26
20
|
|
27
|
-
|
21
|
+
This gem allows you to DRY up your code and forget about including dynamic values in your cache keys.
|
28
22
|
|
29
23
|
## Usage
|
30
|
-
|
24
|
+
After adding the gem to your Gemfile, configure CacheWithSettings in an initializer. You can specify any dynamic cache keys, such as `I18n.locale`.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
CacheWithSettings.configure do |config|
|
28
|
+
config.cache_keys = [I18n.locale.to_s, MoneyRails.default_currency.to_s]
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
That's it! Your template `cache` calls now automatically include the specified cache keys.
|
31
33
|
|
32
34
|
## Installation
|
33
35
|
Add this line to your application's Gemfile:
|
@@ -41,8 +43,8 @@ And then execute:
|
|
41
43
|
$ bundle
|
42
44
|
```
|
43
45
|
|
44
|
-
##
|
45
|
-
|
46
|
+
## Credit
|
47
|
+
This project started as a fork of [cache_with_locale](https://github.com/igorkasyanchuk/cache_with_locale). Besides the locale I also needed the current currency as part of our cache keys, which led to the creation of this gem.
|
46
48
|
|
47
49
|
## License
|
48
50
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -1,26 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "bundler/setup"
|
3
5
|
rescue LoadError
|
4
|
-
puts
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
5
7
|
end
|
6
8
|
|
7
|
-
require
|
9
|
+
require "rdoc/task"
|
8
10
|
|
9
11
|
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir =
|
11
|
-
rdoc.title =
|
12
|
-
rdoc.options <<
|
13
|
-
rdoc.rdoc_files.include(
|
14
|
-
rdoc.rdoc_files.include(
|
12
|
+
rdoc.rdoc_dir = "rdoc"
|
13
|
+
rdoc.title = "CacheWithSettings"
|
14
|
+
rdoc.options << "--line-numbers"
|
15
|
+
rdoc.rdoc_files.include("README.md")
|
16
|
+
rdoc.rdoc_files.include("lib/**/*.rb")
|
15
17
|
end
|
16
18
|
|
17
|
-
require
|
19
|
+
require "bundler/gem_tasks"
|
18
20
|
|
19
|
-
require
|
21
|
+
require "rake/testtask"
|
20
22
|
|
21
23
|
Rake::TestTask.new(:test) do |t|
|
22
|
-
t.libs <<
|
23
|
-
t.pattern =
|
24
|
+
t.libs << "test"
|
25
|
+
t.pattern = "test/**/*_test.rb"
|
24
26
|
t.verbose = false
|
25
27
|
end
|
26
28
|
|
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module CacheWithSettings
|
2
4
|
class Railtie < ::Rails::Railtie
|
3
|
-
initializer
|
5
|
+
initializer "rails_db.helpers" do
|
4
6
|
ActiveSupport.on_load :action_view do
|
5
7
|
ActionView::Base.send :include, CacheWithSettings::Helpers
|
6
8
|
end
|
data/lib/cache_with_settings.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cache_with_settings/configuration"
|
1
4
|
require "cache_with_settings/railtie"
|
2
|
-
require "money-rails"
|
3
5
|
|
4
6
|
module CacheWithSettings
|
5
7
|
module Helpers
|
@@ -10,8 +12,8 @@ module CacheWithSettings
|
|
10
12
|
end
|
11
13
|
|
12
14
|
private
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
def cache_with_settings_compose_key(key)
|
16
|
+
Array.wrap(key).concat(CacheWithSettings.cache_keys)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_with_settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Richard Venneman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -25,13 +25,27 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rubocop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.68'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "<"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.68'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-rails_config
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
|
-
type: :
|
48
|
+
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
@@ -52,10 +66,10 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
|
-
description:
|
56
|
-
|
69
|
+
description: Configure any values such as the application locale to be part of Rails
|
70
|
+
fragment caching cache keys.
|
57
71
|
email:
|
58
|
-
-
|
72
|
+
- richardvenneman@me.com
|
59
73
|
executables: []
|
60
74
|
extensions: []
|
61
75
|
extra_rdoc_files: []
|
@@ -64,10 +78,11 @@ files:
|
|
64
78
|
- README.md
|
65
79
|
- Rakefile
|
66
80
|
- lib/cache_with_settings.rb
|
81
|
+
- lib/cache_with_settings/configuration.rb
|
67
82
|
- lib/cache_with_settings/railtie.rb
|
68
83
|
- lib/cache_with_settings/version.rb
|
69
84
|
- lib/tasks/cache_with_settings_tasks.rake
|
70
|
-
homepage: https://github.com/
|
85
|
+
homepage: https://github.com/richardvenneman
|
71
86
|
licenses:
|
72
87
|
- MIT
|
73
88
|
metadata: {}
|
@@ -89,5 +104,5 @@ requirements: []
|
|
89
104
|
rubygems_version: 3.0.3
|
90
105
|
signing_key:
|
91
106
|
specification_version: 4
|
92
|
-
summary:
|
107
|
+
summary: Configurable Rails fragment caching
|
93
108
|
test_files: []
|