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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 08f7517649396422ab4bc56217543fff26eb0606
4
- data.tar.gz: 7c6c3843e075d0a8b78af06ce75e644b072446ad
3
+ metadata.gz: fe4487fd08e056465fcd49196abf9fe4609d337a
4
+ data.tar.gz: 9211896fdb64b86b240f30a21aa7d9fbd246837a
5
5
  SHA512:
6
- metadata.gz: e07af94417290aad36f97135a2fb6295e77388b531d7ef8d97c9bf14238cc08c8230ef3ad1ccc308d977d1c94f02edc60fc1ab5764db7745ef2d2c1b37e6d4fd
7
- data.tar.gz: 42114c0e2a352d15770d5564a2196cf279ff9a90d71ab59226ceea90e2ae20a7071011c46730b1c894ee0502410282aab8cebb2e3bafba5e51189a814a7ba1d0
6
+ metadata.gz: a1fe74f163bd669b8542429a8db4ab093bb6bf488dd77c494c1425c7a79ec81c0b70fca401f2e33ea6066e6da8fe29351548fad3de26d50ad2de054429c972df
7
+ data.tar.gz: 1b75a29c4826b5e4f79e5fceb9dc7e1ebe264f1892b0dbf2cdacdf5ffcef2c46df06e8b19a127ea2cd530e098dc2c609e45f7819a8015bb5c4069bf086e0bbdf
data/.travis.yml CHANGED
@@ -3,7 +3,6 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
5
  - 2.1.1
6
- - ruby-head
7
6
  - rbx
8
7
  - rbx-2.2.6
9
8
  services:
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module LookupBy
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -614,3 +614,4 @@ CREATE UNIQUE INDEX paths__u_path ON paths USING btree (path);
614
614
  SET search_path TO "$user",public;
615
615
 
616
616
  INSERT INTO schema_migrations (version) VALUES ('20121019040009');
617
+
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lookup_by
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Peterson