lookup_by 0.4.0 → 0.4.1

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: 9abc479376127852eaf37e13d6f22beb0f1a999c
4
- data.tar.gz: 408f965a099b14d4347e4e73325b523d8f4a5cd6
3
+ metadata.gz: 08f7517649396422ab4bc56217543fff26eb0606
4
+ data.tar.gz: 7c6c3843e075d0a8b78af06ce75e644b072446ad
5
5
  SHA512:
6
- metadata.gz: 42434d1b8fd18acf4ebce529e9dabd6669fed6f7b25bf82b7acdd6239fad9fde4a17d24403c843f16cbf0ace8bc28fa1d72c96ae8f5761cc0a4ef3610c6a38f0
7
- data.tar.gz: 25db84500203fb4084b6b518a578f8160ca349320059b1c8513b039629f4ce23f6dbefb97b17aea8b370af503ebb777382849b16407b7a664dfad60b88363749
6
+ metadata.gz: e07af94417290aad36f97135a2fb6295e77388b531d7ef8d97c9bf14238cc08c8230ef3ad1ccc308d977d1c94f02edc60fc1ab5764db7745ef2d2c1b37e6d4fd
7
+ data.tar.gz: 42114c0e2a352d15770d5564a2196cf279ff9a90d71ab59226ceea90e2ae20a7071011c46730b1c894ee0502410282aab8cebb2e3bafba5e51189a814a7ba1d0
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ spec/dummy/tmp/
9
9
  spec/dummy/.sass-cache
10
10
  coverage/
11
11
  Gemfile.lock
12
+ tags
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.1.0
1
+ ruby-2.1.1
data/.travis.yml CHANGED
@@ -2,10 +2,10 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.0-preview1
5
+ - 2.1.1
6
6
  - ruby-head
7
7
  - rbx
8
- - rbx-2.2.1
8
+ - rbx-2.2.6
9
9
  services:
10
10
  - postgresql
11
11
  before_script:
data/Gemfile CHANGED
@@ -18,25 +18,6 @@ group :development, :test do
18
18
  gem "pry", require: false
19
19
  gem 'colored', require: false
20
20
 
21
- platform :rbx do
22
- gem 'racc'
23
- gem 'json'
24
-
25
- # Simplecov and Coveralls
26
- gem 'rubysl-coverage'
27
- gem 'rubinius-coverage'
28
-
29
- # Pry
30
- gem 'rubysl-readline'
31
-
32
- # Rails
33
- gem 'rubysl-base64'
34
- gem 'rubysl-benchmark'
35
- gem 'rubysl-bigdecimal'
36
- gem 'rubysl-digest'
37
- gem 'rubysl-ipaddr'
38
- gem 'rubysl-logger'
39
- gem 'rubysl-mutex_m'
40
- gem 'rubysl-singleton'
41
- end
21
+ gem 'racc'
22
+ gem 'json'
42
23
  end
data/README.md CHANGED
@@ -14,12 +14,13 @@
14
14
  [codeclimate]: https://codeclimate.com/github/companygardener/lookup_by
15
15
  [gittip]: https://www.gittip.com/companygardener
16
16
 
17
- ### Description
17
+ # Overview
18
18
 
19
- LookupBy is a thread-safe lookup table cache for ActiveRecord that reduces normalization pains which features:
19
+ LookupBy is a thread-safe lookup table cache for ActiveRecord that reduces normalization pains and supports:
20
20
 
21
- * a configurable lookup column
22
- * caching (read-through, write-through, Least Recently Used (LRU))
21
+ * configurable column names
22
+ * caching (read-through, write-through, least recently used (LRU))
23
+ * symbols
23
24
 
24
25
  ### Dependencies
25
26
 
@@ -44,22 +45,24 @@ If you find a security bug, please **_do not_** use the issue tracker. Instead,
44
45
 
45
46
  Please create [Issues][issues] to submit bug reports and feature requests.
46
47
 
47
- _Provide a failing rspec test concisely demonstrates the issue._
48
+ _Provide a failing rspec test that concisely demonstrates the issue._
48
49
 
49
- ### Feature requests
50
+ # Installation
50
51
 
51
- ## Installation
52
+ Add this line to your application's Gemfile:
52
53
 
53
- # in Gemfile
54
54
  gem "lookup_by"
55
55
 
56
+ And then execute:
57
+
56
58
  $ bundle
57
59
 
58
60
  Or install it manually:
59
61
 
60
62
  $ gem install lookup_by
61
63
 
62
- ## Usage / Configuration
64
+
65
+ # Usage
63
66
 
64
67
  ### ActiveRecord Plugin
65
68
 
@@ -78,13 +81,23 @@ lookup_for :status
78
81
 
79
82
  ```ruby
80
83
  # db/migrate/201301010012_create_statuses_table.rb
81
- create_table :statuses do |t|
82
- t.string :status, null: false
84
+ create_table :statuses, primary_key: :status_id do |t|
85
+ t.text :status, null: false
83
86
  end
84
87
 
85
88
  # Or use the shorthand
86
89
  create_lookup_table :statuses
87
90
 
91
+ # UUID primary key
92
+ # options[:id] = :uuid
93
+ #
94
+ # SMALLSERIAL primary key
95
+ # options[:small] = true
96
+ #
97
+ # Change the lookup column
98
+ # options[:lookup_column] = "phone_number"
99
+ # options[:lookup_type] = :phone
100
+
88
101
  # app/models/status.rb
89
102
  class Status < ActiveRecord::Base
90
103
  lookup_by :status
@@ -94,7 +107,7 @@ end
94
107
  Status.new(name: "paid")
95
108
  ```
96
109
 
97
- ### Associations / Foreign Keys
110
+ ### Define an association
98
111
 
99
112
  ```ruby
100
113
  # db/migrate/201301010123_create_orders_table.rb
@@ -108,7 +121,7 @@ class Order < ActiveRecord::Base
108
121
  end
109
122
  ```
110
123
 
111
- Provides accessors to use the `status` attribute transparently:
124
+ LookupBy creates methods that use the `status` attribute transparently:
112
125
 
113
126
  ```ruby
114
127
  order = Order.new(status: "paid")
@@ -132,6 +145,8 @@ Order.column_names
132
145
  => ["order_id", "status_id"]
133
146
  ```
134
147
 
148
+ # Configuration
149
+
135
150
  ### Symbolize
136
151
 
137
152
  Casts the attribute to a symbol. Enables the setter to take a symbol.
@@ -172,7 +187,7 @@ lookup_for :status, strict: false
172
187
 
173
188
  The default is no caching. You can also cache all records or use an LRU.
174
189
 
175
- _Note: caching is __per process__, make sure you think through the implications._
190
+ _Note: caching is **per process**, make sure you think through the implications._
176
191
 
177
192
  ```ruby
178
193
  # No caching - Not very useful
@@ -194,7 +209,9 @@ lookup_by :column_name, cache: true
194
209
  lookup_by :column_name, cache: 50
195
210
  ```
196
211
 
197
- ### Configure cache misses
212
+ ### Cache miss
213
+
214
+ You can enable read-throughs using the `:find` option.
198
215
 
199
216
  ```ruby
200
217
  # Return nil
@@ -210,7 +227,11 @@ lookup_by :column_name, cache: 10
210
227
  lookup_by :column_name, cache: true, find: true
211
228
  ```
212
229
 
213
- ### Configure database misses
230
+ ### DB miss
231
+
232
+ You can enable write-throughs using the `:find_or_create` option.
233
+
234
+ _Note: This will only work if the primary key is a sequence and all columns but the lookup column are optional._
214
235
 
215
236
  ```ruby
216
237
  # Return nil
@@ -220,8 +241,6 @@ lookup_by :column_name
220
241
  # Find or create
221
242
  # Useful for user-submitted fields that grow over time
222
243
  # e.g. user_agents, ip_addresses
223
- #
224
- # Note: Only works if attributes are nullable
225
244
  lookup_by :column_name, cache: 20, find_or_create: true
226
245
  ```
227
246
 
@@ -281,23 +300,34 @@ To run the test suite:
281
300
  rake app:db:test:prepare
282
301
  rake
283
302
 
284
- # Giving Back
285
-
286
- ### Contributing
287
-
288
- 1. Fork
289
- 2. Create a feature branch `git checkout -b new-hotness`
290
- 3. Commit your changes `git commit -am 'Added some feature'`
291
- 4. Push to the branch `git push origin new-hotness`
292
- 5. Create a Pull Request
303
+ # Contribute
293
304
 
294
- ### Attribution
305
+ 1. Fork
306
+ 2. Create a feature branch `git checkout -b new-hotness`
307
+ 3. Commit your changes `git commit -am 'Added some feature'`
308
+ 4. Push to the branch `git push origin new-hotness`
309
+ 5. Create a Pull Request
295
310
 
296
311
  A list of authors can be found on the [Contributors][] page.
297
312
 
313
+ # License
314
+
298
315
  Copyright © 2014 Erik Peterson
299
316
 
300
- Released under the MIT License. See [MIT-LICENSE][license] file for more details.
317
+ MIT License
318
+
319
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
320
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
321
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
322
+ persons to whom the Software is furnished to do so, subject to the following conditions:
323
+
324
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
325
+ Software.
326
+
327
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
328
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
329
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
330
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
301
331
 
302
332
  [development]: http://github.com/companygardener/lookup_by "LookupBy Development"
303
333
  [issues]: http://github.com/companygardener/lookup_by/issues "LookupBy Issues"
@@ -133,8 +133,12 @@ module LookupBy
133
133
  table_options = options.slice(:primary_key, :id)
134
134
  table_options[:primary_key] ||= table.singularize + '_id'
135
135
 
136
+ table_options[:id] = false if options[:small]
137
+
136
138
  create_table name, table_options do |t|
137
- t.send lookup_type, lookup_column, null: false
139
+ t.column table_options[:primary_key], 'smallserial primary key' if options[:small]
140
+
141
+ t.column lookup_column, lookup_type, null: false
138
142
 
139
143
  yield t if block_given?
140
144
  end
@@ -1,3 +1,3 @@
1
1
  module LookupBy
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
data/lookup_by.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.description = %q(Use database lookup tables in AR models.)
13
13
 
14
14
  gem.authors = ["Erik Peterson"]
15
- gem.email = ["erik@enova.com"]
15
+ gem.email = ["thecompanygardener@gmail.com"]
16
16
 
17
17
  gem.homepage = "https://www.github.com/companygardener/lookup_by"
18
18
  gem.license = "MIT"
@@ -6,7 +6,7 @@ class CreateTables < ActiveRecord::Migration
6
6
  create_lookup_table :email_addresses
7
7
 
8
8
  create_lookup_table :accounts
9
- create_lookup_table :statuses
9
+ create_lookup_table :statuses, small: true
10
10
 
11
11
  create_lookup_table :ip_addresses, lookup_type: :inet
12
12
 
@@ -270,7 +270,7 @@ ALTER SEQUENCE states_state_id_seq OWNED BY states.state_id;
270
270
  --
271
271
 
272
272
  CREATE TABLE statuses (
273
- status_id integer NOT NULL,
273
+ status_id smallint NOT NULL,
274
274
  status text NOT NULL
275
275
  );
276
276
 
@@ -42,6 +42,10 @@ describe LookupBy::Lookup do
42
42
 
43
43
  subject[" paid "].id.should == status.id
44
44
  end
45
+
46
+ it "has a small primary key" do
47
+ expect { Status.create(status_id: 100_000, status: "too_big") }.to raise_error
48
+ end
45
49
  end
46
50
 
47
51
  context "EmailAddress.lookup_by :column, find_or_create: true" do
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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Peterson
@@ -54,14 +54,13 @@ dependencies:
54
54
  version: '0'
55
55
  description: Use database lookup tables in AR models.
56
56
  email:
57
- - erik@enova.com
57
+ - thecompanygardener@gmail.com
58
58
  executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
63
  - ".ruby-version"
64
- - ".rvmrc"
65
64
  - ".travis.yml"
66
65
  - Gemfile
67
66
  - MIT-LICENSE
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-2.0.0-p353@lookup_by --create