cache_with_locale 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8053fbf9254e9c31cfbd29a34cd493d7483cc1f6
4
+ data.tar.gz: 5d89b8c7592b608dd2a91b32f3b32bec78f6a26e
5
+ SHA512:
6
+ metadata.gz: 475b02be9f67857cbb14d86800ee8bfabaeb0f823026494b137712d2d840413b09a26e6b14840bb01b85ef006339bbdf695847279c88a840bf2782381489d6ff
7
+ data.tar.gz: 7d83a20aa01be4180b178000ed486e4c67f35f7361a50d2bb5fc344e66da1eb30853084a6d1a254eb5799ebc480223cf1c60dc7a8d36e0a47a6da8819a5b331a
@@ -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.
@@ -0,0 +1,48 @@
1
+ [![Build Status](https://travis-ci.org/igorkasyanchuk/cache_with_locale.svg?branch=master)](https://travis-ci.org/igorkasyanchuk/cache_with_locale)
2
+
3
+ # Rails cache with locale
4
+ Automatically adding current application locale (I18n.locale) as a part of caching key in Rails views.
5
+
6
+ ## Problem & Solution
7
+ For example you have:
8
+ - Rails app with different locales
9
+ - you want to add fragment caching in views
10
+
11
+ When you have a different locales and you adding a caching you writing code like this
12
+
13
+ ```
14
+ = cache [@user, I18n.locale] do
15
+ = render @user
16
+ ```
17
+
18
+ As you see you need to add `I18n.locale` as a part of caching 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_locale'
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).
@@ -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 = 'CacheWithLocale'
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,16 @@
1
+ require "cache_with_locale/railtie"
2
+
3
+ module CacheWithLocale
4
+ module Helpers
5
+ def cache(key, options = {}, &block)
6
+ super(cache_with_locale_compose_key(key), options) do
7
+ yield(block)
8
+ end
9
+ end
10
+
11
+ private
12
+ def cache_with_locale_compose_key(key)
13
+ Array.wrap(key) + [I18n.locale.to_s]
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module CacheWithLocale
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'rails_db.helpers' do
4
+ ActiveSupport.on_load :action_view do
5
+ ActionView::Base.send :include, CacheWithLocale::Helpers
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module CacheWithLocale
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :cache_with_locale do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cache_with_locale
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: 2018-06-18 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: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Automatically add application locale (I18n.locale) as a part of cache
42
+ key in Rails views.
43
+ email:
44
+ - igorkasyanchuk@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - MIT-LICENSE
50
+ - README.md
51
+ - Rakefile
52
+ - lib/cache_with_locale.rb
53
+ - lib/cache_with_locale/railtie.rb
54
+ - lib/cache_with_locale/version.rb
55
+ - lib/tasks/cache_with_locale_tasks.rake
56
+ homepage: https://github.com/igorkasyanchuk
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.6.14
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Automatic fragment caching in Rails with locales
80
+ test_files: []