group_cache_key 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +20 -0
- data/README.rdoc +40 -0
- data/Rakefile +4 -51
- data/VERSION +1 -1
- data/group_cache_key.gemspec +17 -0
- data/test/group_cache_key_test.rb +37 -0
- data/test/test_helper.rb +6 -0
- metadata +71 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc40700ca6ecb2215c11b21b3778984a75181b50
|
4
|
+
data.tar.gz: 261a5584b5c3b67f945fbfa997d7cf3bcfc39f66
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88219993ac4f836a29a28ca9e4508cd13cd60021484d2c53378e0284af73566effbe3dd97c94d36862a0541b36b38e080ab40d7dc85777db73c50b5f39319137
|
7
|
+
data.tar.gz: 6fc22b227765b3ca7bdc1ba58e4452d764c25e82eab92d721b09c6cab4bc237be9aaf2f33e958a0b0344936539b6ce8915301e66af268aab6e3861e8fda5a671
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
group_cache_key (0.4.1)
|
5
|
+
activerecord
|
6
|
+
activesupport
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (3.2.13)
|
12
|
+
activesupport (= 3.2.13)
|
13
|
+
builder (~> 3.0.0)
|
14
|
+
activerecord (3.2.13)
|
15
|
+
activemodel (= 3.2.13)
|
16
|
+
activesupport (= 3.2.13)
|
17
|
+
arel (~> 3.0.2)
|
18
|
+
tzinfo (~> 0.3.29)
|
19
|
+
activesupport (3.2.13)
|
20
|
+
i18n (= 0.6.1)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
arel (3.0.2)
|
23
|
+
builder (3.0.4)
|
24
|
+
i18n (0.6.1)
|
25
|
+
minitest (4.7.0)
|
26
|
+
multi_json (1.7.2)
|
27
|
+
rake (10.0.4)
|
28
|
+
tzinfo (0.3.37)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
group_cache_key!
|
35
|
+
minitest
|
36
|
+
rake
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jim Gay
|
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,40 @@
|
|
1
|
+
= group_cache_key
|
2
|
+
|
3
|
+
Using this gem in an application using ActiveRecord will provide you with a 'cache_key'
|
4
|
+
method on collections of models.
|
5
|
+
|
6
|
+
The 'cache_key' will consist of:
|
7
|
+
|
8
|
+
* the tableized name of the class of the first item
|
9
|
+
* an MD5 hash of the ids in the collection
|
10
|
+
* to_i on the max created_at date
|
11
|
+
* to_i on the max updated_at date
|
12
|
+
|
13
|
+
The 'cache_key' should look like:
|
14
|
+
|
15
|
+
'widgets/100-81dc9bdb52d04dc20036dbd8313ed055-1256853629-1256853637'
|
16
|
+
|
17
|
+
The resulting cache_key will be different if your group is sorted differently because
|
18
|
+
the MD5 hash is created according to the order given: no sorting is done to create the hash.
|
19
|
+
|
20
|
+
If your collection is empty, the cache_key will return a key with the object_id. A
|
21
|
+
cache_key for an empty collection will look like:
|
22
|
+
|
23
|
+
'empty/13149280'
|
24
|
+
|
25
|
+
Built by Saturn Flyer http://www.saturnflyer.com
|
26
|
+
|
27
|
+
== Note on Patches/Pull Requests
|
28
|
+
|
29
|
+
* Fork the project.
|
30
|
+
* Make your feature addition or bug fix.
|
31
|
+
* Add tests for it. This is important so I don't break it in a
|
32
|
+
future version unintentionally.
|
33
|
+
* Commit, do not mess with rakefile, version, or history.
|
34
|
+
(if you want to have your own version, that is fine but
|
35
|
+
bump version in a commit by itself I can ignore when I pull)
|
36
|
+
* Send me a pull request. Bonus points for topic branches.
|
37
|
+
|
38
|
+
== Copyright
|
39
|
+
|
40
|
+
Copyright (c) 2009 Jim Gay. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,58 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
2
3
|
require 'rake'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "group_cache_key"
|
8
|
-
gem.summary = %Q{adds a cache_key method to ActiveRecord arrays}
|
9
|
-
gem.description = %Q{adds a cache_key method to ActiveRecord arrays}
|
10
|
-
gem.email = "jim@saturnflyer.com"
|
11
|
-
gem.homepage = "http://github.com/saturnflyer/group_cache_key"
|
12
|
-
gem.authors = ["Jim Gay"]
|
13
|
-
gem.add_dependency 'activerecord', '>=2.1.0'
|
14
|
-
gem.add_dependency 'activesupport', '>=2.1.0'
|
15
|
-
# gem.add_development_dependency "thoughtbot-shoulda"
|
16
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
-
end
|
18
|
-
rescue LoadError
|
19
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
-
end
|
21
|
-
|
22
4
|
require 'rake/testtask'
|
23
|
-
Rake::TestTask.new(:test) do |test|
|
24
|
-
test.libs << 'lib' << 'test'
|
25
|
-
test.pattern = 'test/**/*_test.rb'
|
26
|
-
test.verbose = true
|
27
|
-
end
|
28
|
-
|
29
|
-
begin
|
30
|
-
require 'rcov/rcovtask'
|
31
|
-
Rcov::RcovTask.new do |test|
|
32
|
-
test.libs << 'test'
|
33
|
-
test.pattern = 'test/**/*_test.rb'
|
34
|
-
test.verbose = true
|
35
|
-
end
|
36
|
-
rescue LoadError
|
37
|
-
task :rcov do
|
38
|
-
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
task :test => :check_dependencies
|
43
5
|
|
44
6
|
task :default => :test
|
45
7
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
version = File.read('VERSION')
|
50
|
-
else
|
51
|
-
version = ""
|
52
|
-
end
|
53
|
-
|
54
|
-
rdoc.rdoc_dir = 'rdoc'
|
55
|
-
rdoc.title = "group_cache_key #{version}"
|
56
|
-
rdoc.rdoc_files.include('README*')
|
57
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
8
|
+
Rake::TestTask.new do |t|
|
9
|
+
t.libs << 'test'
|
10
|
+
t.pattern = 'test/*_test.rb'
|
58
11
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "group_cache_key"
|
3
|
+
s.version = "0.4.1"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Jim Gay", "Clemens Gruber", "Patrick Schmitz"]
|
6
|
+
s.email = "jim@saturnflyer.com"
|
7
|
+
s.summary = "Adds cache_key to collections"
|
8
|
+
s.homepage = "http://github.com/saturnflyer/group_cache_key"
|
9
|
+
|
10
|
+
s.add_dependency "activerecord"
|
11
|
+
s.add_dependency "activesupport"
|
12
|
+
|
13
|
+
s.add_development_dependency "rake"
|
14
|
+
s.add_development_dependency "minitest"
|
15
|
+
|
16
|
+
s.files = Dir["#{File.dirname(__FILE__)}/**/*"]
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Widget < ActiveRecord::Base
|
4
|
+
def self.columns
|
5
|
+
[]
|
6
|
+
end
|
7
|
+
attr_accessor :now
|
8
|
+
def updated_at
|
9
|
+
@now ||= Time.now
|
10
|
+
end
|
11
|
+
def created_at
|
12
|
+
@now ||= Time.now
|
13
|
+
end
|
14
|
+
def id
|
15
|
+
object_id
|
16
|
+
end
|
17
|
+
def self.empty_find
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
def self.find
|
21
|
+
[self.new, self.new]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class GroupCacheKeyTest < MiniTest::Unit::TestCase
|
26
|
+
def test_empty_collection_should_return_unique_string_representation
|
27
|
+
@widgets = Widget.empty_find
|
28
|
+
assert_equal("empty/#{@widgets.object_id}", @widgets.cache_key)
|
29
|
+
end
|
30
|
+
def test_collection_should_return_unique_string_with_count_hash_and_timestamps
|
31
|
+
@widgets = Widget.find
|
32
|
+
hash = Digest::MD5.hexdigest(@widgets.collect{|w| w.id}.to_s)
|
33
|
+
created = @widgets.first.created_at.to_i.to_s
|
34
|
+
updated = @widgets.first.updated_at.to_i.to_s
|
35
|
+
assert_equal("widgets/#{@widgets.length}-#{hash}-#{created}-#{updated}", @widgets.cache_key)
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,26 +1,90 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: group_cache_key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Gay
|
8
8
|
- Clemens Gruber
|
9
|
+
- Patrick Schmitz
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
13
|
date: 2013-03-25 00:00:00.000000000 Z
|
13
|
-
dependencies:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: activerecord
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: activesupport
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: minitest
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
14
71
|
description:
|
15
|
-
email:
|
72
|
+
email: jim@saturnflyer.com
|
16
73
|
executables: []
|
17
74
|
extensions: []
|
18
75
|
extra_rdoc_files: []
|
19
76
|
files:
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
|
77
|
+
- ./Gemfile
|
78
|
+
- ./Gemfile.lock
|
79
|
+
- ./group_cache_key.gemspec
|
80
|
+
- ./lib/group_cache_key.rb
|
81
|
+
- ./LICENSE
|
82
|
+
- ./Rakefile
|
83
|
+
- ./README.rdoc
|
84
|
+
- ./test/group_cache_key_test.rb
|
85
|
+
- ./test/test_helper.rb
|
86
|
+
- ./VERSION
|
87
|
+
homepage: http://github.com/saturnflyer/group_cache_key
|
24
88
|
licenses: []
|
25
89
|
metadata: {}
|
26
90
|
post_install_message:
|