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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d44fc8b425cf60789dbf23b7ba588d2b70d57717162e486b45f833fc8a3ead51
4
- data.tar.gz: '0396f825129a23dfc5c732e24c0951f281c7107f78bb16f3b6b9177c249dd936'
3
+ metadata.gz: c0afd8964a34b654ac33eb73501f28bff8e170667452b409749e48902bca8e7a
4
+ data.tar.gz: 3adbf5daaad4d0c8213205aab8b6ec24c38c1f123df18b64707b8429816709b4
5
5
  SHA512:
6
- metadata.gz: 412ae33ce3aa025d4932ad39e18a382a14853f98c0f9326de9fc90f923cb549c84e8001e80ad25f1fc66f3dfb793d91642a0fd63875ca2972a5320f23f3bb4f1
7
- data.tar.gz: b5a18a25e2f0426c61660a46e8ec02248e4a1cb20308d5518671dd8ade8b6e2036c6bc77abc4729f3bad7b6d7f39841b5ef718f2498c1c1b58951c560d88e7e7
6
+ metadata.gz: 12e521466bbbe4494339c7e79ebebee5b3ba40d3e568f60bc56eb0116e69adc5ad703f81d9974e7873c23fec05c38f8bdf71404405ffdc58e932a9ec3cb7a542
7
+ data.tar.gz: bbfcbac8a8dde1644024bf5353ed6d618574a23baad684a8c7cc1dfd23592ba110d94e1288effecc7f0141db6dbd610f35642c6e73c71eeec18e4fd4ba9d932e
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2018 Igor Kasyanchuk
1
+ Copyright 2018 Richard Venneman
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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 cache with settings
4
- 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. So this gem automatically adds the current locale (I18n.locale) and currency (MoneyRails.default_currency) as parts of caching keys in Rails views.
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
- For example you have:
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
- As you see you need to add `I18n.locale` and `MoneyRails.default_currency` as a part of the cache key. And you need to do it everywhere. What if you forget about it in some view?
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
- And let gem handle all work. You don't need to specify locale as a cache sufix/prefix.
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
- Just add this gem to your Gemfile.
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
- ## Contributing
45
- Contribution directions go here.
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 'bundler/setup'
4
+ require "bundler/setup"
3
5
  rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
7
  end
6
8
 
7
- require 'rdoc/task'
9
+ require "rdoc/task"
8
10
 
9
11
  RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = 'rdoc'
11
- rdoc.title = 'CacheWithSettings'
12
- rdoc.options << '--line-numbers'
13
- rdoc.rdoc_files.include('README.md')
14
- rdoc.rdoc_files.include('lib/**/*.rb')
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 'bundler/gem_tasks'
19
+ require "bundler/gem_tasks"
18
20
 
19
- require 'rake/testtask'
21
+ require "rake/testtask"
20
22
 
21
23
  Rake::TestTask.new(:test) do |t|
22
- t.libs << 'test'
23
- t.pattern = 'test/**/*_test.rb'
24
+ t.libs << "test"
25
+ t.pattern = "test/**/*_test.rb"
24
26
  t.verbose = false
25
27
  end
26
28
 
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CacheWithSettings
4
+ mattr_accessor :cache_keys
5
+ self.cache_keys = []
6
+
7
+ def self.configure
8
+ yield self
9
+ end
10
+ end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CacheWithSettings
2
4
  class Railtie < ::Rails::Railtie
3
- initializer 'rails_db.helpers' do
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CacheWithSettings
2
- VERSION = '0.0.1'
4
+ VERSION = "1.0.0"
3
5
  end
@@ -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
- def cache_with_settings_compose_key(key)
14
- Array.wrap(key).concat([I18n.locale.to_s, MoneyRails.default_currency.to_s])
15
- end
15
+ def cache_with_settings_compose_key(key)
16
+ Array.wrap(key).concat(CacheWithSettings.cache_keys)
17
+ end
16
18
  end
17
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # desc "Explaining what the task does"
2
4
  # task :cache_with_settings do
3
5
  # # Task goes here
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.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Igor Kasyanchuk
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: money-rails
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: :runtime
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: Automatically add application locale (I18n.locale) as a part of cache
56
- key in Rails views.
69
+ description: Configure any values such as the application locale to be part of Rails
70
+ fragment caching cache keys.
57
71
  email:
58
- - igorkasyanchuk@gmail.com
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/igorkasyanchuk
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: Automatic fragment caching in Rails with locales
107
+ summary: Configurable Rails fragment caching
93
108
  test_files: []