cachers 4.1.0.2 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +114 -0
  4. data/Rakefile +1 -3
  5. data/lib/cachers.rb +2 -2
  6. data/lib/cachers/concern.rb +3 -2
  7. data/lib/cachers/dsl.rb +1 -1
  8. data/lib/cachers/extensions/active_record/base.rb +1 -1
  9. data/lib/cachers/railtie.rb +0 -6
  10. data/lib/cachers/version.rb +1 -1
  11. data/lib/generators/cachers/install/install_generator.rb +1 -1
  12. data/{test/dummy/config → lib/generators/cachers/install/templates}/redis.yml +0 -0
  13. metadata +17 -114
  14. data/lib/generators/cachers/install/templates/configuration.yml +0 -15
  15. data/test/dummy/Rakefile +0 -5
  16. data/test/dummy/app/assets/javascripts/application.js +0 -13
  17. data/test/dummy/app/assets/stylesheets/application.css +0 -15
  18. data/test/dummy/app/cachers/user_cacher.rb +0 -24
  19. data/test/dummy/app/controllers/application_controller.rb +0 -5
  20. data/test/dummy/app/helpers/application_helper.rb +0 -2
  21. data/test/dummy/app/models/user.rb +0 -2
  22. data/test/dummy/app/views/layouts/application.html.erb +0 -12
  23. data/test/dummy/bin/bundle +0 -4
  24. data/test/dummy/bin/rails +0 -5
  25. data/test/dummy/bin/rake +0 -5
  26. data/test/dummy/bin/setup +0 -30
  27. data/test/dummy/config.ru +0 -4
  28. data/test/dummy/config/application.rb +0 -25
  29. data/test/dummy/config/boot.rb +0 -5
  30. data/test/dummy/config/database.yml +0 -10
  31. data/test/dummy/config/database.yml.travis +0 -3
  32. data/test/dummy/config/environment.rb +0 -5
  33. data/test/dummy/config/environments/development.rb +0 -41
  34. data/test/dummy/config/environments/production.rb +0 -79
  35. data/test/dummy/config/environments/test.rb +0 -42
  36. data/test/dummy/config/initializers/assets.rb +0 -11
  37. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  38. data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
  39. data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  40. data/test/dummy/config/initializers/inflections.rb +0 -16
  41. data/test/dummy/config/initializers/mime_types.rb +0 -4
  42. data/test/dummy/config/initializers/session_store.rb +0 -3
  43. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  44. data/test/dummy/config/locales/en.yml +0 -23
  45. data/test/dummy/config/routes.rb +0 -56
  46. data/test/dummy/config/secrets.yml +0 -22
  47. data/test/dummy/db/migrate/20160918232127_create_users.rb +0 -9
  48. data/test/dummy/db/schema.rb +0 -25
  49. data/test/dummy/log/development.log +0 -21
  50. data/test/dummy/log/test.log +0 -2007
  51. data/test/dummy/public/404.html +0 -61
  52. data/test/dummy/public/422.html +0 -61
  53. data/test/dummy/public/500.html +0 -60
  54. data/test/dummy/public/favicon.ico +0 -0
  55. data/test/generator_test.rb +0 -25
  56. data/test/model_test.rb +0 -27
  57. data/test/record_test.rb +0 -29
  58. data/test/task_test.rb +0 -35
  59. data/test/test_helper.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2a5dd5608ba6ae1efe233c8166880def5667638e
4
- data.tar.gz: 8fb91ee8790642dee3cdcea75d86cc5a0ff38e93
3
+ metadata.gz: ba951b8f855fd479feffad68fec3a05863460c65
4
+ data.tar.gz: 8174a0df81007c58fc53b1c4302f177d6a56baad
5
5
  SHA512:
6
- metadata.gz: 3cc1dfa4213725c8b7843c8cb902005f136d48e54f3492ea415d39dcecfa670d0d102e075c8d5781f16ee55e64a35b1dfadc0b2d4e116c513202c4f4d7225716
7
- data.tar.gz: 3c018e1f5690f43a4916b5cbaaa94f1d9eb0512d0329fb0296f5723c047ca9c8365fe90e4fea9cbb6fa47882bbfb79ecdaf48453e249e88573b3fbd68abfa0fa
6
+ metadata.gz: 735007953decb93c41a32a445c4f62529fe3b5b9f680ba9bd3a7935ca3f26734934e5cc070d21db1b6b3e58b2832e82076e490154127db782073423647704b71
7
+ data.tar.gz: 057357ff0ffecf0cfe7af22f07dc6f61904bb1f755c8a24afb36786837bdfc6f382f6bba7e46bf01bde576e62138b0d19b948fa4782f31b79006f33602a251cb
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2016 Mathías Montossi
1
+ Copyright 2017 Museways
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 ADDED
@@ -0,0 +1,114 @@
1
+ [![Gem Version](https://badge.fury.io/rb/cachers.svg)](http://badge.fury.io/rb/cachers)
2
+ [![Code Climate](https://codeclimate.com/github/museways/cachers/badges/gpa.svg)](https://codeclimate.com/github/museways/cachers)
3
+ [![Build Status](https://travis-ci.org/museways/cachers.svg)](https://travis-ci.org/museways/cachers)
4
+ [![Dependency Status](https://gemnasium.com/museways/cachers.svg)](https://gemnasium.com/museways/cachers)
5
+
6
+ # Cachers
7
+
8
+ Dedicated classes to isolate redis logic in rails.
9
+
10
+ ## Why
11
+
12
+ I did this gem to:
13
+
14
+ - Prevent models to have too much code.
15
+ - Have a convention of how to use cache in models.
16
+ - Increase atomization in complex projects.
17
+
18
+ ## Install
19
+
20
+ Put this line in your Gemfile:
21
+ ```ruby
22
+ gem 'cachers'
23
+ ```
24
+
25
+ Then bundle:
26
+ ```
27
+ $ bundle
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ ### Definitions
33
+
34
+ Generate a cacher for a model:
35
+ ```
36
+ $ bundle exec rails g cacher like
37
+ ```
38
+
39
+ Add the logic to the cache and uncache methods:
40
+ ```ruby
41
+ class LikeCacher < Cachers::Base
42
+
43
+ def cache
44
+ sadd key, record.product.id
45
+ end
46
+
47
+ def uncache
48
+ srem key, record.product.id
49
+ end
50
+
51
+ private
52
+
53
+ def key
54
+ "users/#{record.user.id}/likes"
55
+ end
56
+
57
+ end
58
+ ```
59
+
60
+ NOTE: Updates work automatically, there is no need to add a method to replace values.
61
+
62
+ ### Custom methods
63
+
64
+ You may want to add some other methods related to the cache:
65
+ ```ruby
66
+ class UserCacher < Cachers::Base
67
+
68
+ def likes?(product)
69
+ sismember key, product.id
70
+ end
71
+
72
+ private
73
+
74
+ def key
75
+ "users/#{record.id}/likes"
76
+ end
77
+
78
+ end
79
+ ```
80
+
81
+ The public methods will be available to call directly from the model:
82
+ ```ruby
83
+ user.likes? product
84
+ ```
85
+
86
+ ### Cache management
87
+
88
+ If you want to manually control the cache, you can use this methods:
89
+ ```ruby
90
+ user.cache
91
+ user.recache
92
+ user.uncache
93
+ ```
94
+
95
+ Or to it for all cacheable records:
96
+ ```
97
+ $ bundle exec rake cachers:cache
98
+ $ bundle exec rake cachers:recache
99
+ $ bundle exec rake cachers:uncache
100
+ ```
101
+
102
+ ## Contributing
103
+
104
+ Any issue, pull request, comment of any kind is more than welcome!
105
+
106
+ I will mainly ensure compatibility to Rails, AWS, PostgreSQL, Redis, Elasticsearch and FreeBSD. 
107
+
108
+ ## Credits
109
+
110
+ This gem is maintained and funded by [museways](https://github.com/museways).
111
+
112
+ ## License
113
+
114
+ It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.
data/Rakefile CHANGED
@@ -4,16 +4,14 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
- Bundler::GemHelper.install_tasks
7
+ require 'bundler/gem_tasks'
8
8
 
9
9
  require 'rake/testtask'
10
10
 
11
11
  Rake::TestTask.new(:test) do |t|
12
- t.libs << 'lib'
13
12
  t.libs << 'test'
14
13
  t.pattern = 'test/**/*_test.rb'
15
14
  t.verbose = false
16
- t.warning = false
17
15
  end
18
16
 
19
17
  task default: :test
data/lib/cachers.rb CHANGED
@@ -9,8 +9,8 @@ require 'cachers/version'
9
9
  module Cachers
10
10
  class << self
11
11
 
12
- def client
13
- @client ||= begin
12
+ def redis
13
+ @redis ||= begin
14
14
  require 'redis'
15
15
  Redis.new YAML.load_file("#{Rails.root}/config/redis.yml")[Rails.env]
16
16
  end
@@ -1,9 +1,11 @@
1
1
  module Cachers
2
2
  module Concern
3
3
  extend ActiveSupport::Concern
4
- include Delegation
5
4
 
6
5
  included do
6
+ %i(extend include).each do |action|
7
+ send action, Delegation
8
+ end
7
9
  after_commit :cache, on: :create
8
10
  after_commit :recache, on: :update
9
11
  after_commit :uncache, on: :destroy
@@ -14,7 +16,6 @@ module Cachers
14
16
  end
15
17
 
16
18
  module ClassMethods
17
- include Delegation
18
19
 
19
20
  def cacher
20
21
  "#{name}Cacher".constantize
data/lib/cachers/dsl.rb CHANGED
@@ -2,7 +2,7 @@ module Cachers
2
2
  module Dsl
3
3
 
4
4
  def method_missing(name, *args, &block)
5
- Cachers.client.send name, *args, &block
5
+ Cachers.redis.send name, *args, &block
6
6
  end
7
7
 
8
8
  end
@@ -8,7 +8,7 @@ module Cachers
8
8
 
9
9
  def inherited(subclass)
10
10
  super
11
- if subclass.name && File.exist?("#{Rails.root}/app/cachers/#{subclass.name.underscore}_cacher.rb")
11
+ if File.exist?("#{Rails.root}/app/cachers/#{subclass.name.underscore}_cacher.rb")
12
12
  subclass.include Cachers::Concern
13
13
  end
14
14
  end
@@ -1,12 +1,6 @@
1
1
  module Cachers
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- config.before_initialize do
5
- Dir["#{Rails.root}/app/cachers/**/*_cacher.rb"].each do |file|
6
- load file
7
- end
8
- end
9
-
10
4
  initializer 'cachers.active_record' do
11
5
  ActiveSupport.on_load :active_record do
12
6
  ::ActiveRecord::Base.include(
@@ -1,5 +1,5 @@
1
1
  module Cachers
2
2
 
3
- VERSION = '4.1.0.2'
3
+ VERSION = '5.1.1'
4
4
 
5
5
  end
@@ -7,7 +7,7 @@ module Cachers
7
7
  source_root File.expand_path('../templates', __FILE__)
8
8
 
9
9
  def create_configuration_file
10
- copy_file 'configuration.yml', 'config/redis.yml'
10
+ copy_file 'redis.yml', 'config/redis.yml'
11
11
  end
12
12
 
13
13
  end
metadata CHANGED
@@ -1,71 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cachers
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.2
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - mmontossi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-14 00:00:00.000000000 Z
11
+ date: 2017-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 4.2.0
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: 4.3.0
19
+ version: '5.1'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 4.2.0
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: 4.3.0
26
+ version: '5.1'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: pg
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
31
  - - "~>"
38
32
  - !ruby/object:Gem::Version
39
- version: '0.18'
33
+ version: '0.21'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
38
  - - "~>"
45
39
  - !ruby/object:Gem::Version
46
- version: '0.18'
40
+ version: '0.21'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: redis
49
43
  requirement: !ruby/object:Gem::Requirement
50
44
  requirements:
51
45
  - - "~>"
52
46
  - !ruby/object:Gem::Version
53
- version: '3.2'
47
+ version: '3.3'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
51
  requirements:
58
52
  - - "~>"
59
53
  - !ruby/object:Gem::Version
60
- version: '3.2'
54
+ version: '3.3'
61
55
  description: Dedicated classes to isolate redis logic in rails.
62
56
  email:
63
- - mmontossi@gmail.com
57
+ - hi@museways.com
64
58
  executables: []
65
59
  extensions: []
66
60
  extra_rdoc_files: []
67
61
  files:
68
62
  - MIT-LICENSE
63
+ - README.md
69
64
  - Rakefile
70
65
  - lib/cachers.rb
71
66
  - lib/cachers/base.rb
@@ -78,55 +73,9 @@ files:
78
73
  - lib/generators/cachers/cacher/cacher_generator.rb
79
74
  - lib/generators/cachers/cacher/templates/cacher.rb
80
75
  - lib/generators/cachers/install/install_generator.rb
81
- - lib/generators/cachers/install/templates/configuration.yml
76
+ - lib/generators/cachers/install/templates/redis.yml
82
77
  - lib/tasks/cachers.rake
83
- - test/dummy/Rakefile
84
- - test/dummy/app/assets/javascripts/application.js
85
- - test/dummy/app/assets/stylesheets/application.css
86
- - test/dummy/app/cachers/user_cacher.rb
87
- - test/dummy/app/controllers/application_controller.rb
88
- - test/dummy/app/helpers/application_helper.rb
89
- - test/dummy/app/models/user.rb
90
- - test/dummy/app/views/layouts/application.html.erb
91
- - test/dummy/bin/bundle
92
- - test/dummy/bin/rails
93
- - test/dummy/bin/rake
94
- - test/dummy/bin/setup
95
- - test/dummy/config.ru
96
- - test/dummy/config/application.rb
97
- - test/dummy/config/boot.rb
98
- - test/dummy/config/database.yml
99
- - test/dummy/config/database.yml.travis
100
- - test/dummy/config/environment.rb
101
- - test/dummy/config/environments/development.rb
102
- - test/dummy/config/environments/production.rb
103
- - test/dummy/config/environments/test.rb
104
- - test/dummy/config/initializers/assets.rb
105
- - test/dummy/config/initializers/backtrace_silencers.rb
106
- - test/dummy/config/initializers/cookies_serializer.rb
107
- - test/dummy/config/initializers/filter_parameter_logging.rb
108
- - test/dummy/config/initializers/inflections.rb
109
- - test/dummy/config/initializers/mime_types.rb
110
- - test/dummy/config/initializers/session_store.rb
111
- - test/dummy/config/initializers/wrap_parameters.rb
112
- - test/dummy/config/locales/en.yml
113
- - test/dummy/config/redis.yml
114
- - test/dummy/config/routes.rb
115
- - test/dummy/config/secrets.yml
116
- - test/dummy/db/migrate/20160918232127_create_users.rb
117
- - test/dummy/db/schema.rb
118
- - test/dummy/log/development.log
119
- - test/dummy/log/test.log
120
- - test/dummy/public/404.html
121
- - test/dummy/public/422.html
122
- - test/dummy/public/500.html
123
- - test/dummy/public/favicon.ico
124
- - test/generator_test.rb
125
- - test/model_test.rb
126
- - test/record_test.rb
127
- - test/task_test.rb
128
- - test/test_helper.rb
129
- homepage: https://github.com/mmontossi/cachers
78
+ homepage: https://github.com/museways/cachers
130
79
  licenses:
131
80
  - MIT
132
81
  metadata: {}
@@ -138,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
87
  requirements:
139
88
  - - ">="
140
89
  - !ruby/object:Gem::Version
141
- version: 2.1.0
90
+ version: '0'
142
91
  required_rubygems_version: !ruby/object:Gem::Requirement
143
92
  requirements:
144
93
  - - ">="
@@ -146,54 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
95
  version: '0'
147
96
  requirements: []
148
97
  rubyforge_project:
149
- rubygems_version: 2.5.1
98
+ rubygems_version: 2.6.13
150
99
  signing_key:
151
100
  specification_version: 4
152
101
  summary: Cachers for rails
153
- test_files:
154
- - test/dummy/app/assets/javascripts/application.js
155
- - test/dummy/app/assets/stylesheets/application.css
156
- - test/dummy/app/cachers/user_cacher.rb
157
- - test/dummy/app/controllers/application_controller.rb
158
- - test/dummy/app/helpers/application_helper.rb
159
- - test/dummy/app/models/user.rb
160
- - test/dummy/app/views/layouts/application.html.erb
161
- - test/dummy/bin/bundle
162
- - test/dummy/bin/rails
163
- - test/dummy/bin/rake
164
- - test/dummy/bin/setup
165
- - test/dummy/config/application.rb
166
- - test/dummy/config/boot.rb
167
- - test/dummy/config/database.yml
168
- - test/dummy/config/database.yml.travis
169
- - test/dummy/config/environment.rb
170
- - test/dummy/config/environments/development.rb
171
- - test/dummy/config/environments/production.rb
172
- - test/dummy/config/environments/test.rb
173
- - test/dummy/config/initializers/assets.rb
174
- - test/dummy/config/initializers/backtrace_silencers.rb
175
- - test/dummy/config/initializers/cookies_serializer.rb
176
- - test/dummy/config/initializers/filter_parameter_logging.rb
177
- - test/dummy/config/initializers/inflections.rb
178
- - test/dummy/config/initializers/mime_types.rb
179
- - test/dummy/config/initializers/session_store.rb
180
- - test/dummy/config/initializers/wrap_parameters.rb
181
- - test/dummy/config/locales/en.yml
182
- - test/dummy/config/redis.yml
183
- - test/dummy/config/routes.rb
184
- - test/dummy/config/secrets.yml
185
- - test/dummy/config.ru
186
- - test/dummy/db/migrate/20160918232127_create_users.rb
187
- - test/dummy/db/schema.rb
188
- - test/dummy/log/development.log
189
- - test/dummy/log/test.log
190
- - test/dummy/public/404.html
191
- - test/dummy/public/422.html
192
- - test/dummy/public/500.html
193
- - test/dummy/public/favicon.ico
194
- - test/dummy/Rakefile
195
- - test/generator_test.rb
196
- - test/model_test.rb
197
- - test/record_test.rb
198
- - test/task_test.rb
199
- - test/test_helper.rb
102
+ test_files: []