group_cache_key 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.rdoc +5 -0
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/lib/group_cache_key.rb +1 -1
- data/test/group_cache_key_test.rb +32 -2
- data/test/test_helper.rb +0 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/README.rdoc
CHANGED
@@ -16,6 +16,11 @@ The 'cache_key' should look like:
|
|
16
16
|
|
17
17
|
The resulting cache_key will be different if your group is sorted differently because
|
18
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'
|
19
24
|
|
20
25
|
Built by Saturn Flyer http://www.saturnflyer.com
|
21
26
|
|
data/Rakefile
CHANGED
@@ -10,8 +10,8 @@ begin
|
|
10
10
|
gem.email = "jim@saturnflyer.com"
|
11
11
|
gem.homepage = "http://github.com/saturnflyer/group_cache_key"
|
12
12
|
gem.authors = ["Jim Gay"]
|
13
|
-
gem.add_dependency 'activerecord'
|
14
|
-
gem.add_dependency 'activesupport'
|
13
|
+
gem.add_dependency 'activerecord', '>=2.1.0'
|
14
|
+
gem.add_dependency 'activesupport', '>=2.1.0'
|
15
15
|
# gem.add_development_dependency "thoughtbot-shoulda"
|
16
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
17
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/group_cache_key.rb
CHANGED
@@ -6,7 +6,7 @@ ActiveRecord::Base.class_eval {
|
|
6
6
|
Array.class_eval {
|
7
7
|
def cache_key
|
8
8
|
if self.empty?
|
9
|
-
'empty'
|
9
|
+
'empty/' + self.object_id.to_s
|
10
10
|
else
|
11
11
|
ids_hash = Digest::MD5.hexdigest(self.collect{|item| item.id }.to_s)
|
12
12
|
update_timestamp = max {|a,b| a.updated_at <=> b.updated_at }.updated_at.to_i.to_s
|
@@ -1,7 +1,37 @@
|
|
1
1
|
require 'test_helper'
|
2
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
|
+
|
3
25
|
class GroupCacheKeyTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
|
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)
|
6
36
|
end
|
7
37
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: group_cache_key
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Gay
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 2.1.0
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: activesupport
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 2.1.0
|
34
34
|
version:
|
35
35
|
description: adds a cache_key method to ActiveRecord arrays
|
36
36
|
email: jim@saturnflyer.com
|