cache_with_settings 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d44fc8b425cf60789dbf23b7ba588d2b70d57717162e486b45f833fc8a3ead51
4
+ data.tar.gz: '0396f825129a23dfc5c732e24c0951f281c7107f78bb16f3b6b9177c249dd936'
5
+ SHA512:
6
+ metadata.gz: 412ae33ce3aa025d4932ad39e18a382a14853f98c0f9326de9fc90f923cb549c84e8001e80ad25f1fc66f3dfb793d91642a0fd63875ca2972a5320f23f3bb4f1
7
+ data.tar.gz: b5a18a25e2f0426c61660a46e8ec02248e4a1cb20308d5518671dd8ade8b6e2036c6bc77abc4729f3bad7b6d7f39841b5ef718f2498c1c1b58951c560d88e7e7
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Igor Kasyanchuk
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ [![Build Status](https://travis-ci.org/richardvenneman/cache_with_settings.svg?branch=master)](https://travis-ci.org/richardvenneman/cache_with_settings)
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.
5
+
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:
12
+
13
+ ```
14
+ = cache [@user, I18n.locale, MoneyRails.default_currency] do
15
+ = render @user
16
+ ```
17
+
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
21
+
22
+ ```
23
+ = cache @user do
24
+ = render @user
25
+ ```
26
+
27
+ And let gem handle all work. You don't need to specify locale as a cache sufix/prefix.
28
+
29
+ ## Usage
30
+ Just add this gem to your Gemfile.
31
+
32
+ ## Installation
33
+ Add this line to your application's Gemfile:
34
+
35
+ ```ruby
36
+ gem 'cache_with_settings'
37
+ ```
38
+
39
+ And then execute:
40
+ ```bash
41
+ $ bundle
42
+ ```
43
+
44
+ ## Contributing
45
+ Contribution directions go here.
46
+
47
+ ## License
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ 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')
15
+ end
16
+
17
+ require 'bundler/gem_tasks'
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/**/*_test.rb'
24
+ t.verbose = false
25
+ end
26
+
27
+ task default: :test
@@ -0,0 +1,17 @@
1
+ require "cache_with_settings/railtie"
2
+ require "money-rails"
3
+
4
+ module CacheWithSettings
5
+ module Helpers
6
+ def cache(key, options = {}, &block)
7
+ super(cache_with_settings_compose_key(key), options) do
8
+ yield(block)
9
+ end
10
+ end
11
+
12
+ 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
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module CacheWithSettings
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'rails_db.helpers' do
4
+ ActiveSupport.on_load :action_view do
5
+ ActionView::Base.send :include, CacheWithSettings::Helpers
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module CacheWithSettings
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cache_with_settings do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache_with_settings
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Igor Kasyanchuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: money-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Automatically add application locale (I18n.locale) as a part of cache
56
+ key in Rails views.
57
+ email:
58
+ - igorkasyanchuk@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - lib/cache_with_settings.rb
67
+ - lib/cache_with_settings/railtie.rb
68
+ - lib/cache_with_settings/version.rb
69
+ - lib/tasks/cache_with_settings_tasks.rake
70
+ homepage: https://github.com/igorkasyanchuk
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.3
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Automatic fragment caching in Rails with locales
93
+ test_files: []