prosto_cache 0.2.3 → 0.2.4
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.
- data/lib/prosto_cache/prosto_model_cache.rb +7 -11
- data/spec/prosto_cache_spec.rb +0 -24
- metadata +3 -3
|
@@ -137,11 +137,10 @@ module ProstoCache
|
|
|
137
137
|
|
|
138
138
|
cache_values = model_class.all
|
|
139
139
|
self.cache = build_cache(cache_values, accessor_keys)
|
|
140
|
-
self.validated_at = time
|
|
141
|
-
self.signature = current_cache_signature
|
|
142
|
-
|
|
143
140
|
cache.values(sorted_cache_values(cache_values))
|
|
144
141
|
cache.keys(sorted_keys(cache.values))
|
|
142
|
+
self.validated_at = time
|
|
143
|
+
self.signature = current_cache_signature
|
|
145
144
|
end
|
|
146
145
|
|
|
147
146
|
|
|
@@ -170,9 +169,8 @@ module ProstoCache
|
|
|
170
169
|
|
|
171
170
|
def sorted_cache_values(cache_values)
|
|
172
171
|
cache_values.sort_by { |o|
|
|
173
|
-
sort_keys.
|
|
174
|
-
|
|
175
|
-
memo << sort_key if sort_key
|
|
172
|
+
sort_keys.inject('') { |memo, k|
|
|
173
|
+
memo << o.public_send(k)
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
176
|
end
|
|
@@ -180,9 +178,7 @@ module ProstoCache
|
|
|
180
178
|
def sorted_keys(cache_values)
|
|
181
179
|
cache_values.map { |o|
|
|
182
180
|
accessor_keys.inject([]) { |memo, k|
|
|
183
|
-
|
|
184
|
-
raise BadCacheValuesError, "Null key '#{k}' found in value #{o.inspect}" unless sort_key
|
|
185
|
-
memo << sort_key.to_sym
|
|
181
|
+
memo << o.public_send(k).to_sym
|
|
186
182
|
}
|
|
187
183
|
}.tap { |rtn|
|
|
188
184
|
rtn.flatten! if accessor_keys.length == 1
|
|
@@ -198,10 +194,10 @@ module ProstoCache
|
|
|
198
194
|
[].tap { |rows| raw_result.each_hash { |h| rows << h } }
|
|
199
195
|
when 'Mysql2::Result'
|
|
200
196
|
[].tap { |rows| raw_result.each(:as => :hash) { |h| rows << h } }
|
|
201
|
-
when 'PGresult'
|
|
197
|
+
when 'PGresult', 'PG::Result'
|
|
202
198
|
raw_result.map(&:to_hash)
|
|
203
199
|
else
|
|
204
|
-
fail "Result class #{raw_result.class.name}
|
|
200
|
+
fail "Result class #{raw_result.class.name} is unsupported"
|
|
205
201
|
end
|
|
206
202
|
array_result.map(&:symbolize_keys).first
|
|
207
203
|
end
|
data/spec/prosto_cache_spec.rb
CHANGED
|
@@ -45,14 +45,6 @@ describe ProstoCache::ProstoModelCache do
|
|
|
45
45
|
it "should return all keys from the cache" do
|
|
46
46
|
model_class.cache.keys.should == [:bar, :foo]
|
|
47
47
|
end
|
|
48
|
-
|
|
49
|
-
context 'when key for one of the rows is nil' do
|
|
50
|
-
it "should raise meaningful error" do
|
|
51
|
-
model_class.should_receive(:all).once.and_return(['foo', nil].map { |n| model_class.new(n) })
|
|
52
|
-
|
|
53
|
-
expect { model_class.cache.keys }.to raise_error ProstoCache::BadCacheValuesError
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
48
|
end
|
|
57
49
|
|
|
58
50
|
describe "#values" do
|
|
@@ -69,14 +61,6 @@ describe ProstoCache::ProstoModelCache do
|
|
|
69
61
|
values.map(&:name).should == %w(bar foo)
|
|
70
62
|
end
|
|
71
63
|
|
|
72
|
-
context 'when key for one of the rows is nil' do
|
|
73
|
-
it "should raise meaningful error" do
|
|
74
|
-
model_class.should_receive(:all).once.and_return(['foo', nil].map { |n| model_class.new(n) })
|
|
75
|
-
|
|
76
|
-
expect { model_class.cache.values }.to raise_error ProstoCache::BadCacheValuesError
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
64
|
context 'when sort_keys are provided' do
|
|
81
65
|
let(:model_class) {
|
|
82
66
|
Class.new {
|
|
@@ -114,14 +98,6 @@ describe ProstoCache::ProstoModelCache do
|
|
|
114
98
|
model_class.cache[:foo]
|
|
115
99
|
end
|
|
116
100
|
|
|
117
|
-
context 'when key for one of the rows is nil' do
|
|
118
|
-
it "should raise meaningful error when other key is accessed" do
|
|
119
|
-
model_class.should_receive(:all).once.and_return(['foo', nil].map { |n| model_class.new(n) })
|
|
120
|
-
|
|
121
|
-
expect { model_class.cache[:foo] }.to raise_error ProstoCache::BadCacheValuesError
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
101
|
context 'when key is symbol' do
|
|
126
102
|
it "should raise an error for key that was not found" do
|
|
127
103
|
expect { model_class.cache[:nondef] }.to raise_error ProstoCache::BadCacheKeyError
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: prosto_cache
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.4
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2014-04-07 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rspec
|
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
83
83
|
version: 1.3.6
|
|
84
84
|
requirements: []
|
|
85
85
|
rubyforge_project:
|
|
86
|
-
rubygems_version: 1.8.23
|
|
86
|
+
rubygems_version: 1.8.23.2
|
|
87
87
|
signing_key:
|
|
88
88
|
specification_version: 3
|
|
89
89
|
summary: Very simple caching for your ActiveRecord models.
|