lookup_by 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/lib/lookup_by/cache.rb +12 -0
- data/lib/lookup_by/version.rb +1 -1
- data/spec/dummy/db/structure.sql +1 -0
- data/spec/lookup_by_spec.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe4487fd08e056465fcd49196abf9fe4609d337a
|
4
|
+
data.tar.gz: 9211896fdb64b86b240f30a21aa7d9fbd246837a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1fe74f163bd669b8542429a8db4ab093bb6bf488dd77c494c1425c7a79ec81c0b70fca401f2e33ea6066e6da8fe29351548fad3de26d50ad2de054429c972df
|
7
|
+
data.tar.gz: 1b75a29c4826b5e4f79e5fceb9dc7e1ebe264f1892b0dbf2cdacdf5ffcef2c46df06e8b19a127ea2cd530e098dc2c609e45f7819a8015bb5c4069bf086e0bbdf
|
data/.travis.yml
CHANGED
data/lib/lookup_by/cache.rb
CHANGED
@@ -55,12 +55,24 @@ module LookupBy
|
|
55
55
|
@cache.clear
|
56
56
|
end
|
57
57
|
|
58
|
+
def create(*args, &block)
|
59
|
+
created = @klass.create(*args, &block)
|
60
|
+
@cache[created.id] = created if created && cache?
|
61
|
+
created
|
62
|
+
end
|
63
|
+
|
58
64
|
def create!(*args, &block)
|
59
65
|
created = @klass.create!(*args, &block)
|
60
66
|
@cache[created.id] = created if cache?
|
61
67
|
created
|
62
68
|
end
|
63
69
|
|
70
|
+
def seed(*values)
|
71
|
+
@klass.transaction(requires_new: true) do
|
72
|
+
values.each { |value| create!(@field => value) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
64
76
|
def fetch(value)
|
65
77
|
increment :cache, :get
|
66
78
|
|
data/lib/lookup_by/version.rb
CHANGED
data/spec/dummy/db/structure.sql
CHANGED
data/spec/lookup_by_spec.rb
CHANGED
@@ -15,9 +15,20 @@ describe ::ActiveRecord::Base do
|
|
15
15
|
|
16
16
|
it { should respond_to :name }
|
17
17
|
end
|
18
|
+
|
18
19
|
end
|
19
20
|
|
20
21
|
describe LookupBy::Lookup do
|
22
|
+
describe "cache" do
|
23
|
+
it "seeds values" do
|
24
|
+
City.lookup.seed 'Boston'
|
25
|
+
City.lookup.seed 'Chicago', 'New York City'
|
26
|
+
|
27
|
+
City.all.map(&:name).sort.should eq(['Boston', 'Chicago', 'New York City'])
|
28
|
+
City.lookup.clear
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
21
32
|
context "City.lookup_by :column" do
|
22
33
|
subject { City }
|
23
34
|
|