lookup_by 0.10.6 → 0.10.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/gemfiles/rails_4.0.gemfile +1 -1
- data/gemfiles/rails_4.1.gemfile +1 -1
- data/gemfiles/rails_4.2.gemfile +1 -1
- data/lib/lookup_by/cache.rb +2 -2
- data/lib/lookup_by/lookup.rb +1 -1
- data/lib/lookup_by/version.rb +1 -1
- data/spec/caching/lru_spec.rb +2 -2
- data/spec/lookup_by_spec.rb +23 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f66e8cfacf984285ac5c1a39050c953e59727cf
|
4
|
+
data.tar.gz: 88e26f09abcb787959662658bd1cf941337dd1e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b3f2d7a4ea2d2dde3d9ef4f90b72e78003d1e0c63aa60487cff6132d7042cf467de1fdd3c56f04960c2c61a132b143c2d820c07164a43d10067d838a3f95162
|
7
|
+
data.tar.gz: 63c97a2f17ac275aed7732d8419fbe626d9cb6bf884a1997336a175638c1b76d24fc4319cccb814b78db6cec6812b2cc930a289f10842488ff3c30b5ee0fe743
|
data/Gemfile
CHANGED
data/gemfiles/rails_4.0.gemfile
CHANGED
data/gemfiles/rails_4.1.gemfile
CHANGED
data/gemfiles/rails_4.2.gemfile
CHANGED
data/lib/lookup_by/cache.rb
CHANGED
@@ -202,14 +202,14 @@ module LookupBy
|
|
202
202
|
return unless object
|
203
203
|
|
204
204
|
@mutex.synchronize do
|
205
|
-
@reverse[object.send(@field)] = @cache[object.id] = object
|
205
|
+
@reverse[object.send(@field).to_s] = @cache[object.id] = object
|
206
206
|
end
|
207
207
|
end
|
208
208
|
else
|
209
209
|
def cache_write(object)
|
210
210
|
return unless object
|
211
211
|
|
212
|
-
@reverse[object.send(@field)] = @cache[object.id] = object
|
212
|
+
@reverse[object.send(@field).to_s] = @cache[object.id] = object
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
data/lib/lookup_by/lookup.rb
CHANGED
@@ -98,7 +98,7 @@ module LookupBy
|
|
98
98
|
when Symbol then @lookup.fetch(arg.to_s)
|
99
99
|
when IPAddr then @lookup.fetch(arg.to_s)
|
100
100
|
when self then arg
|
101
|
-
else raise TypeError, "#{name}[
|
101
|
+
else raise TypeError, "#{name}[*args]: args must be at least one String, Symbol, Integer, IPAddr, nil, or #{name}"
|
102
102
|
end
|
103
103
|
else return args.map { |arg| self[arg] }
|
104
104
|
end
|
data/lib/lookup_by/version.rb
CHANGED
data/spec/caching/lru_spec.rb
CHANGED
@@ -56,7 +56,7 @@ describe LookupBy::Caching::LRU do
|
|
56
56
|
describe "#fetch" do
|
57
57
|
specify { expect(cache.fetch(1)).to eq "one" }
|
58
58
|
specify { expect(cache.fetch(3) { |key| key }).to eq 3 }
|
59
|
-
specify { expect { cache.fetch(3) }.to raise_error }
|
59
|
+
specify { expect { cache.fetch(3) }.to raise_error(KeyError) }
|
60
60
|
|
61
61
|
it "writes missing values" do
|
62
62
|
expect(cache.fetch(3) { "missing" }).to eq "missing"
|
@@ -71,7 +71,7 @@ describe LookupBy::Caching::LRU do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
describe "#max_size=" do
|
74
|
-
specify { expect { cache.max_size = -1 }.to raise_error }
|
74
|
+
specify { expect { cache.max_size = -1 }.to raise_error(ArgumentError) }
|
75
75
|
end
|
76
76
|
|
77
77
|
describe "#size" do
|
data/spec/lookup_by_spec.rb
CHANGED
@@ -87,7 +87,7 @@ end
|
|
87
87
|
describe LookupBy::Lookup do
|
88
88
|
context "Uncacheable.lookup_by :column, cache: true, find_or_create: true" do
|
89
89
|
it "fails when trying to cache and write-through" do
|
90
|
-
expect { Uncacheable }.to raise_error
|
90
|
+
expect { Uncacheable }.to raise_error(ArgumentError)
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
@@ -209,12 +209,30 @@ describe LookupBy::Lookup do
|
|
209
209
|
context "IpAddress.lookup_by :column, cache: N, find_or_create: true" do
|
210
210
|
subject { IpAddress }
|
211
211
|
|
212
|
-
|
213
|
-
|
212
|
+
let(:value) { '127.0.0.1' }
|
213
|
+
let(:ip) { subject[value] }
|
214
214
|
|
215
|
-
|
215
|
+
it "allows lookup by IPAddr" do
|
216
|
+
expect(subject[IPAddr.new(value)]).to eq(ip)
|
217
|
+
expect(subject[ip]).to eq(ip)
|
216
218
|
expect(subject[ip.id]).to eq(ip)
|
217
|
-
expect(subject[
|
219
|
+
expect(subject[value]).to eq(ip)
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'caches values' do
|
223
|
+
subject.lookup.testing = false
|
224
|
+
|
225
|
+
subject[value]
|
226
|
+
|
227
|
+
id1 = subject[IPAddr.new(value)].object_id
|
228
|
+
id2 = subject[ip.id].object_id
|
229
|
+
id3 = subject[value].object_id
|
230
|
+
id4 = subject[ip].object_id
|
231
|
+
|
232
|
+
expect([id1, id2, id3, id4].uniq.size).to eq(1)
|
233
|
+
|
234
|
+
subject.lookup.testing = true
|
235
|
+
subject.lookup.clear
|
218
236
|
end
|
219
237
|
end
|
220
238
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lookup_by
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Erik Peterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
155
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.4.
|
156
|
+
rubygems_version: 2.4.5.1
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: A thread-safe lookup table cache for ActiveRecord
|