incrdecr_cached_counts 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci-matrix.yml +8 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +15 -0
  5. data/Gemfile +21 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.rdoc +51 -0
  8. data/Rakefile +16 -0
  9. data/circle.yml +10 -0
  10. data/html/CachedCounts/ClassMethods.html +960 -0
  11. data/html/CachedCounts/Railtie.html +102 -0
  12. data/html/CachedCounts.html +197 -0
  13. data/html/README_rdoc.html +152 -0
  14. data/html/created.rid +7 -0
  15. data/html/css/fonts.css +167 -0
  16. data/html/css/rdoc.css +590 -0
  17. data/html/fonts/Lato-Light.ttf +0 -0
  18. data/html/fonts/Lato-LightItalic.ttf +0 -0
  19. data/html/fonts/Lato-Regular.ttf +0 -0
  20. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  21. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  22. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  23. data/html/images/add.png +0 -0
  24. data/html/images/arrow_up.png +0 -0
  25. data/html/images/brick.png +0 -0
  26. data/html/images/brick_link.png +0 -0
  27. data/html/images/bug.png +0 -0
  28. data/html/images/bullet_black.png +0 -0
  29. data/html/images/bullet_toggle_minus.png +0 -0
  30. data/html/images/bullet_toggle_plus.png +0 -0
  31. data/html/images/date.png +0 -0
  32. data/html/images/delete.png +0 -0
  33. data/html/images/find.png +0 -0
  34. data/html/images/loadingAnimation.gif +0 -0
  35. data/html/images/macFFBgHack.png +0 -0
  36. data/html/images/package.png +0 -0
  37. data/html/images/page_green.png +0 -0
  38. data/html/images/page_white_text.png +0 -0
  39. data/html/images/page_white_width.png +0 -0
  40. data/html/images/plugin.png +0 -0
  41. data/html/images/ruby.png +0 -0
  42. data/html/images/tag_blue.png +0 -0
  43. data/html/images/tag_green.png +0 -0
  44. data/html/images/transparent.png +0 -0
  45. data/html/images/wrench.png +0 -0
  46. data/html/images/wrench_orange.png +0 -0
  47. data/html/images/zoom.png +0 -0
  48. data/html/index.html +155 -0
  49. data/html/js/darkfish.js +161 -0
  50. data/html/js/jquery.js +4 -0
  51. data/html/js/navigation.js +142 -0
  52. data/html/js/navigation.js.gz +0 -0
  53. data/html/js/search.js +109 -0
  54. data/html/js/search_index.js +1 -0
  55. data/html/js/search_index.js.gz +0 -0
  56. data/html/js/searcher.js +228 -0
  57. data/html/js/searcher.js.gz +0 -0
  58. data/html/table_of_contents.html +144 -0
  59. data/incrdecr_cached_counts.gemspec +31 -0
  60. data/lib/cached_counts/connection_for.rb +14 -0
  61. data/lib/cached_counts/dalli_check.rb +5 -0
  62. data/lib/cached_counts/railtie.rb +7 -0
  63. data/lib/cached_counts/version.rb +3 -0
  64. data/lib/cached_counts.rb +388 -0
  65. data/spec/caches_count_of_spec.rb +142 -0
  66. data/spec/caches_count_where_spec.rb +88 -0
  67. data/spec/database.yml +5 -0
  68. data/spec/fixtures/department.rb +11 -0
  69. data/spec/fixtures/following.rb +7 -0
  70. data/spec/fixtures/university.rb +11 -0
  71. data/spec/fixtures/user.rb +26 -0
  72. data/spec/fixtures.rb +23 -0
  73. data/spec/spec_helper.rb +49 -0
  74. metadata +239 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4c327147e72e3805c900b40be70e55e8fc923a00
4
+ data.tar.gz: d024e41326daa4a2cb92cfa670791bba73f5dd96
5
+ SHA512:
6
+ metadata.gz: 0efe60b65ccd5bfcb6b4c4c083daae3218507ad7430603c587078ab5577de30a1c47427765267e8d73e65831c5515fb9c0e0b22e53e74a2cb3bc38d8f578c9e2
7
+ data.tar.gz: 0945dff72c8025ad3ace58c826c1973d0d9b00dc41f4fd8d62f28e25a12b4172fc546c3e4d34d4b2d79033308febe48a033da5e696ee03768fbadb0e87ce8737
@@ -0,0 +1,8 @@
1
+ env:
2
+ - ACTIVERECORD_VERSION=4.2.6
3
+ - ACTIVERECORD_VERSION=4.1.15
4
+ - ACTIVERECORD_VERSION=4.0.13
5
+
6
+ command:
7
+ - rm -f Gemfile.lock && ACTIVERECORD_VERSION=$ACTIVERECORD_VERSION bundle
8
+ - bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ .bundle/
2
+ log/*.log
3
+ Gemfile.lock
4
+ pkg/
5
+ test/dummy/db/*.sqlite3
6
+ test/dummy/db/*.sqlite3-journal
7
+ test/dummy/log/*.log
8
+ test/dummy/tmp/
9
+ test/dummy/.sass-cache
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ sudo: false # use newer travis infrastructure
2
+ language: ruby
3
+ rvm:
4
+ - "2.1.8"
5
+ - "2.2.4"
6
+ - "2.3.0"
7
+ env:
8
+ - "ACTIVERECORD_VERSION=4.2.6"
9
+ - "ACTIVERECORD_VERSION=4.1.15"
10
+ - "ACTIVERECORD_VERSION=4.0.13"
11
+ - "ACTIVERECORD_VERSION=master"
12
+ matrix:
13
+ allow_failures:
14
+ # Master may or may not pass
15
+ - env: "ACTIVERECORD_VERSION=master"
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Declare your gem's dependencies in cached_counts.gemspec.
4
+ # Bundler will treat runtime dependencies like base dependencies, and
5
+ # development dependencies will be added by default to the :development group.
6
+ gemspec
7
+
8
+ ar_version = ENV["ACTIVERECORD_VERSION"] || "default"
9
+ case ar_version
10
+ when "default"
11
+ # Allow the gemspec to specify
12
+ else
13
+ gem "activerecord", "~> #{ar_version}", group: [:development, :test]
14
+ end
15
+
16
+ # Declare any dependencies that are still in development here instead of in
17
+ # your gemspec. These might include edge Rails or gems from your path or
18
+ # Git. Remember to move these dependencies to your gemspec before releasing
19
+ # your gem to rubygems.org.
20
+
21
+ gem 'pry', group: [:development, :test]
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Academia.edu
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.rdoc ADDED
@@ -0,0 +1,51 @@
1
+ = CachedCounts
2
+
3
+ A replacement for Rails' counter caches, using memcached.
4
+
5
+ Caches counts of models in a scope or association in memcached, and keeps the
6
+ cache up to date using incr/decr operations.
7
+
8
+ You might prefer this gem over Rails' built-in counter caches when:
9
+ * You want to cache the total number of models for a class or scope
10
+ * You have a large association (e.g. followers of a popular figure) and want to avoid contention on a database row
11
+ * You want your caches to expire and be refreshed to mitigate the risk of getting out of sync
12
+ * You don't need to use counts as part of more complex SQL queries
13
+
14
+ There are [many alternatives](https://rubygems.org/search?utf8=%E2%9C%93&query=counter+cache),
15
+ but this gem appears to be unique in making use of memcached's incr/decr operations.
16
+
17
+ = Usage
18
+
19
+ Basic usage:
20
+
21
+ class User < ActiveRecord::Base
22
+ include CachedCounts
23
+
24
+ has_many :followers, class_name: 'Following' #, ...
25
+ scope :confirmed, ->{ where(confirmed: true) }
26
+
27
+ # creates cached class method `User.confirmed_count`
28
+ caches_count_where :confirmed, if: :confirmed?
29
+
30
+ # creates cached instance method `user.followers_count`
31
+ caches_count_of :followers
32
+ end
33
+
34
+ class Following < ActiveRecord::Base
35
+ include CachedCounts
36
+
37
+ belongs_to :followee, class_name: 'User', # ...
38
+ end
39
+
40
+ For full options, see docs for CachedCounts.caches_count_of
41
+ and CachedCounts.caches_count_where.
42
+
43
+ = Licence
44
+
45
+ MIT
46
+
47
+ Copyright Academia.edu
48
+
49
+ = Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/academia-edu/cached_counts
data/Rakefile ADDED
@@ -0,0 +1,16 @@
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
+ RDoc::Task.new do |rdoc|
9
+ rdoc.main = "README.rdoc"
10
+ rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
11
+ end
12
+
13
+ require 'rspec/core/rake_task'
14
+ RSpec::Core::RakeTask.new('spec')
15
+
16
+ task :default => :spec
data/circle.yml ADDED
@@ -0,0 +1,10 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.3
4
+
5
+ dependencies:
6
+ pre:
7
+ - curl -fsSL https://git.io/v2Ifn | bash
8
+
9
+ database:
10
+ override: