lookup_by 0.3.2 → 0.4.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: a299c9db3319e08da624742ac0c273269762509a
4
- data.tar.gz: af001c400ada05593af8aa11a8660ede11998596
3
+ metadata.gz: 9abc479376127852eaf37e13d6f22beb0f1a999c
4
+ data.tar.gz: 408f965a099b14d4347e4e73325b523d8f4a5cd6
5
5
  SHA512:
6
- metadata.gz: 5e3f915965de466e8b2502f0a86950af419161a864d646c0af8450eadd6ed6ee20d192db0c6e9eb446cca25f5dce9753404ab4663d790ee0a7a39fc8d048d163
7
- data.tar.gz: b2a9d2a6bbaa80f4fb7fb414078d37876568b90227abcdd2132db24855f16ec2f8a8d94cf812dcdd13b6da790cf8c7e7f3ab009f4c19a584deff3a62f2142dd9
6
+ metadata.gz: 42434d1b8fd18acf4ebce529e9dabd6669fed6f7b25bf82b7acdd6239fad9fde4a17d24403c843f16cbf0ace8bc28fa1d72c96ae8f5761cc0a4ef3610c6a38f0
7
+ data.tar.gz: 25db84500203fb4084b6b518a578f8160ca349320059b1c8513b039629f4ce23f6dbefb97b17aea8b370af503ebb777382849b16407b7a664dfad60b88363749
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.0.0-p247
1
+ ruby-2.1.0
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 2.0.0-p0@lookup_by --create
1
+ rvm use ruby-2.0.0-p353@lookup_by --create
data/.travis.yml CHANGED
@@ -1,10 +1,15 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
- - 2.0.0-p0
5
- - rbx-19mode
4
+ - 2.0.0
5
+ - 2.1.0-preview1
6
6
  - ruby-head
7
+ - rbx
8
+ - rbx-2.2.1
7
9
  services:
8
10
  - postgresql
9
11
  before_script:
10
- - sh -c "cd spec/dummy && RAILS_ENV=test bundle exec rake db:migrate:reset db:seed"
12
+ - psql -c 'create database lookup_by_test' -U postgres
13
+ script:
14
+ - bundle exec rake app:db:test:prepare
15
+ - bundle exec rake
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Declare your gem's dependencies in lookup_by.gemspec.
4
4
  # Bundler will treat runtime dependencies like base dependencies, and
@@ -6,12 +6,37 @@ source "http://rubygems.org"
6
6
  gemspec
7
7
 
8
8
  group :development, :test do
9
- gem "pry"
10
- gem "rake"
11
- gem "simplecov", require: false
12
- gem "rspec-rails", "~> 2.11.0"
9
+ gem 'rspec'
13
10
  gem 'database_cleaner'
14
11
 
15
12
  gem "pg", platform: :ruby
16
13
  gem "activerecord-jdbcpostgresql-adapter", platform: :jruby
14
+
15
+ gem "simplecov", require: false
16
+ gem 'coveralls', require: false
17
+
18
+ gem "pry", require: false
19
+ gem 'colored', require: false
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
17
42
  end
data/MIT-LICENSE CHANGED
@@ -1,4 +1,6 @@
1
- Copyright © 2012 Erik Peterson, Enova
1
+ Copyright © 2014 Erik Peterson
2
+
3
+ MIT License
2
4
 
3
5
  Permission is hereby granted, free of charge, to any person obtaining
4
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,59 +1,77 @@
1
1
  # LookupBy
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/companygardener/lookup_by.png)](http://travis-ci.org/companygardener/lookup_by)
4
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/companygardener/lookup_by)
3
+ [![Gem Version](https://badge.fury.io/rb/lookup_by.png)][rubygems]
4
+ [![Build Status](https://secure.travis-ci.org/companygardener/lookup_by.png?branch=master)][travis]
5
+ [![Dependency Status](https://gemnasium.com/companygardener/lookup_by.png)][gemnasium]
6
+ [![Coverage Status](https://coveralls.io/repos/companygardener/lookup_by/badge.png?branch=master)][coveralls]
7
+ [![Code Climate](https://codeclimate.com/github/companygardener/lookup_by.png)][codeclimate]
8
+ [![Gittip](http://img.shields.io/gittip/companygardener.png)][gittip]
9
+
10
+ [rubygems]: https://rubygems.org/gems/lookup_by
11
+ [travis]: http://travis-ci.org/companygardener/lookup_by
12
+ [gemnasium]: https://gemnasium.com/companygardener/lookup_by
13
+ [coveralls]: https://coveralls.io/r/companygardener/lookup_by?branch=master
14
+ [codeclimate]: https://codeclimate.com/github/companygardener/lookup_by
15
+ [gittip]: https://www.gittip.com/companygardener
5
16
 
6
17
  ### Description
7
18
 
8
- LookupBy is a thread-safe lookup table cache for ActiveRecord that reduces normalization pains.
19
+ LookupBy is a thread-safe lookup table cache for ActiveRecord that reduces normalization pains which features:
9
20
 
10
- ### Features
21
+ * a configurable lookup column
22
+ * caching (read-through, write-through, Least Recently Used (LRU))
11
23
 
12
- * Thread-safety
13
- * Configurable lookup column
14
- * Caching (read-through, write-through, Least Recently Used (LRU))
15
-
16
- ### Compatibility
24
+ ### Dependencies
17
25
 
26
+ * Rails 3.2+
18
27
  * PostgreSQL
19
28
 
20
29
  ### Development
21
30
 
22
- * [github.com/companygardener/lookup_by][development]
31
+ [github.com/companygardener/lookup_by][development]
23
32
 
24
33
  ### Source
25
34
 
26
- * git clone git://github.com/companygardener/lookup_by.git
35
+ git clone git://github.com/companygardener/lookup_by.git
36
+
37
+ ### Bug reports
38
+
39
+ If you discover a problem with LookupBy, please let me know. However, I ask that you'd kindly review these guidelines before creating [Issues][]:
40
+
41
+ https://github.com/companygardener/lookup_by/wiki/Bug-Reports
42
+
43
+ If you find a security bug, please **_do not_** use the issue tracker. Instead, send an email to: thecompanygardener@gmail.com.
27
44
 
28
- ### Issues
45
+ Please create [Issues][issues] to submit bug reports and feature requests.
29
46
 
30
- Please submit issues to this Github project in the [Issues tab][issues]. _Provide a failing rspec test that works with the existing test suite_.
47
+ _Provide a failing rspec test concisely demonstrates the issue._
48
+
49
+ ### Feature requests
31
50
 
32
51
  ## Installation
33
52
 
34
- ```
35
- # in Gemfile
36
- gem "lookup_by"
53
+ # in Gemfile
54
+ gem "lookup_by"
37
55
 
38
- $ bundle
39
- ```
56
+ $ bundle
40
57
 
41
58
  Or install it manually:
42
59
 
43
60
  $ gem install lookup_by
44
61
 
45
- # Usage / Configuration
62
+ ## Usage / Configuration
46
63
 
47
64
  ### ActiveRecord Plugin
48
65
 
49
- LookupBy adds 2 macro methods to `ActiveRecord::Base`
66
+ LookupBy adds two "macro" methods to `ActiveRecord::Base`
50
67
 
51
68
  ```ruby
52
69
  lookup_by :column_name
53
70
  # Defines .[], .lookup, and .is_a_lookup? class methods.
54
71
 
55
- lookup_for :column_name
56
- # Defines #column_name and #column_name= accessors that transparently reference the lookup table.
72
+ lookup_for :status
73
+ # Defines #status and #status= instance methods that transparently reference the lookup table.
74
+ # Defines .with_status(name) and .with_statuses(*names) scopes on the model.
57
75
  ```
58
76
 
59
77
  ### Define the lookup model
@@ -64,12 +82,15 @@ create_table :statuses do |t|
64
82
  t.string :status, null: false
65
83
  end
66
84
 
85
+ # Or use the shorthand
86
+ create_lookup_table :statuses
87
+
67
88
  # app/models/status.rb
68
89
  class Status < ActiveRecord::Base
69
- lookup_by :status # Replace :status with the name of your lookup column
90
+ lookup_by :status
70
91
  end
71
92
 
72
- # Aliases the lookup attribute to :name.
93
+ # Aliases :name to the lookup attribute
73
94
  Status.new(name: "paid")
74
95
  ```
75
96
 
@@ -87,7 +108,7 @@ class Order < ActiveRecord::Base
87
108
  end
88
109
  ```
89
110
 
90
- Creates accessors to use the `status` attribute transparently:
111
+ Provides accessors to use the `status` attribute transparently:
91
112
 
92
113
  ```ruby
93
114
  order = Order.new(status: "paid")
@@ -95,21 +116,27 @@ order = Order.new(status: "paid")
95
116
  order.status
96
117
  => "paid"
97
118
 
119
+ order.status_id
120
+ => 1
121
+
98
122
  # Access the lookup object
99
123
  order.raw_status
100
- => <#Status id: 1, status: "paid">
124
+ => #<Status id: 1, status: "paid">
101
125
 
102
126
  # Access the lookup value before type casting
103
127
  order.status_before_type_cast
104
128
  => "paid"
129
+
130
+ # Look ma', no strings!
131
+ Order.column_names
132
+ => ["order_id", "status_id"]
105
133
  ```
106
134
 
107
135
  ### Symbolize
108
136
 
109
137
  Casts the attribute to a symbol. Enables the setter to take a symbol.
110
138
 
111
- _This is a bad idea if the set of lookup values is large. Symbols are
112
- never garbage collected._
139
+ _Bad idea when the set of lookup values is large. Symbols are never garbage collected._
113
140
 
114
141
  ```ruby
115
142
  class Order < ActiveRecord::Base
@@ -127,7 +154,7 @@ order.status = :shipped
127
154
 
128
155
  ### Strict
129
156
 
130
- Do you want missing lookup values to raise an error?
157
+ By default, missing lookup values will raise an error.
131
158
 
132
159
  ```ruby
133
160
  # Raise
@@ -137,12 +164,16 @@ lookup_for :status
137
164
  # this will raise a LookupBy::Error
138
165
  Order.status = "non-existent status"
139
166
 
140
- # Set to nil
167
+ # Set to nil instead
141
168
  lookup_for :status, strict: false
142
169
  ```
143
170
 
144
171
  ### Caching
145
172
 
173
+ The default is no caching. You can also cache all records or use an LRU.
174
+
175
+ _Note: caching is __per process__, make sure you think through the implications._
176
+
146
177
  ```ruby
147
178
  # No caching - Not very useful
148
179
  # Default
@@ -151,13 +182,15 @@ lookup_by :column_name
151
182
  # Cache all
152
183
  # Use for a small finite list (e.g. status codes, US states)
153
184
  #
154
- # find: false DEFAULT
185
+ # Defaults to no read-through
186
+ # options[:find] = false
155
187
  lookup_by :column_name, cache: true
156
188
 
157
189
  # Cache N (with LRU eviction)
158
- # Use for a large list with uneven distribution (e.g. email domain, city)
190
+ # Use for large sets with uneven distribution (e.g. email domain, city)
159
191
  #
160
- # find: true DEFAULT and REQUIRED
192
+ # Requires read-through
193
+ # options[:find] = true
161
194
  lookup_by :column_name, cache: 50
162
195
  ```
163
196
 
@@ -187,12 +220,12 @@ lookup_by :column_name
187
220
  # Find or create
188
221
  # Useful for user-submitted fields that grow over time
189
222
  # e.g. user_agents, ip_addresses
190
- #
223
+ #
191
224
  # Note: Only works if attributes are nullable
192
225
  lookup_by :column_name, cache: 20, find_or_create: true
193
226
  ```
194
227
 
195
- ### Normalizing values
228
+ ### Normalize values
196
229
 
197
230
  ```ruby
198
231
  # Normalize
@@ -200,6 +233,16 @@ lookup_by :column_name, cache: 20, find_or_create: true
200
233
  lookup_by :column_name, normalize: true
201
234
  ```
202
235
 
236
+ ### Allow blank
237
+
238
+ Can be useful to handle `params` that are not required.
239
+
240
+ ```ruby
241
+ # Allow blank
242
+ # Treat "" different than nil
243
+ lookup_by :column_name, allow_blank: true
244
+ ```
245
+
203
246
  # Integration
204
247
 
205
248
  ### Cucumber
@@ -235,6 +278,7 @@ This plugin uses rspec and pry for testing. Make sure you have them installed:
235
278
 
236
279
  To run the test suite:
237
280
 
281
+ rake app:db:test:prepare
238
282
  rake
239
283
 
240
284
  # Giving Back
@@ -249,13 +293,13 @@ To run the test suite:
249
293
 
250
294
  ### Attribution
251
295
 
252
- A list of authors can be found on the [LookupBy Contributors page][contributors].
296
+ A list of authors can be found on the [Contributors][] page.
253
297
 
254
- Copyright © 2012 Erik Peterson, Enova
298
+ Copyright © 2014 Erik Peterson
255
299
 
256
300
  Released under the MIT License. See [MIT-LICENSE][license] file for more details.
257
301
 
258
- [development]: http://www.github.com/companygardener/lookup_by "LookupBy Development"
259
- [issues]: http://www.github.com/companygardener/lookup_by/issues "LookupBy Issues"
260
- [license]: http://www.github.com/companygardener/lookup_by/blob/master/MIT-LICENSE "LookupBy License"
302
+ [development]: http://github.com/companygardener/lookup_by "LookupBy Development"
303
+ [issues]: http://github.com/companygardener/lookup_by/issues "LookupBy Issues"
304
+ [license]: http://github.com/companygardener/lookup_by/blob/master/MIT-LICENSE "LookupBy License"
261
305
  [contributors]: http://github.com/companygardener/lookup_by/graphs/contributors "LookupBy Contributors"
data/Rakefile CHANGED
@@ -1,10 +1,12 @@
1
- #!/usr/bin/env rake
2
1
  begin
3
2
  require 'bundler/setup'
4
3
  rescue LoadError
5
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
5
  end
7
6
 
7
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
8
+ load 'rails/tasks/engine.rake'
9
+
8
10
  Bundler::GemHelper.install_tasks
9
11
 
10
12
  require "rspec/core/rake_task"
data/TODO.md CHANGED
@@ -1,16 +1,14 @@
1
- Roadmap
2
- =======
1
+ # Roadmap
3
2
 
4
- * Pluggable backend (memcache, redis, etc.) to reduce memory usage, allow
5
- larger LRUs.
6
- * Additional database support / tests
7
- * Improve LRU algorithm
8
- * Lookup by multiple fields, multi-column unique constraint
3
+ ## Soon
9
4
 
10
- Soon
11
- ====
12
- * Travis CI
13
- * Gemnasium
14
5
  * Require validations / constraints on lookup field (presence, uniqueness)
15
6
  * Trap signal to output stats
16
- * Populate LRU with using the counts of an association
7
+ * Populate LRU with counts grouped by an association
8
+
9
+ ## Someday
10
+
11
+ * Pluggable backend (memcache, redis, etc.) to reduce memory usage, allow larger LRUs.
12
+ * Additional database support / tests
13
+ * Improve LRU algorithm
14
+ * Lookup by multiple fields, multi-column unique constraint
@@ -67,13 +67,11 @@ module LookupBy
67
67
  value = normalize(value) if @normalize && !primary_key?(value)
68
68
 
69
69
  found = cache_read(value) if cache?
70
- found ||= db_read(value) if @read
71
- found ||= db_read(value) if not @enabled
70
+ found ||= db_read(value) if @read || !@enabled
72
71
 
73
72
  @cache[found.id] = found if found && cache?
74
73
 
75
74
  found ||= db_write(value) if @write
76
-
77
75
  found
78
76
  end
79
77
 
@@ -144,12 +142,16 @@ module LookupBy
144
142
  found
145
143
  end
146
144
 
147
- # TODO: Handle race condition on create! failure
148
145
  def db_write(value)
149
146
  column = column_for(value)
150
147
 
151
- found = @klass.create!(column => value) if column != @primary_key
152
- found
148
+ return if column == @primary_key
149
+
150
+ @klass.transaction(requires_new: true) do
151
+ @klass.create!(column => value)
152
+ end
153
+ rescue ActiveRecord::RecordNotUnique
154
+ db_read(value)
153
155
  end
154
156
 
155
157
  def column_for(value)
@@ -1,3 +1,3 @@
1
1
  module LookupBy
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/lookup_by.rb CHANGED
@@ -10,6 +10,7 @@ module LookupBy
10
10
  autoload :Association, "lookup_by/association"
11
11
  autoload :Cache, "lookup_by/cache"
12
12
  autoload :Lookup, "lookup_by/lookup"
13
+ autoload :IPAddr, "ipaddr"
13
14
 
14
15
  module Caching
15
16
  autoload :LRU, "lookup_by/caching/lru"
data/lookup_by.gemspec CHANGED
@@ -1,23 +1,29 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
4
 
4
5
  require "lookup_by/version"
5
6
 
6
7
  Gem::Specification.new do |gem|
7
- gem.name = "lookup_by"
8
- gem.version = LookupBy::VERSION
8
+ gem.name = "lookup_by"
9
+ gem.version = LookupBy::VERSION
9
10
 
10
- gem.summary = %q(A thread-safe lookup table cache for ActiveRecord)
11
- gem.description = %q(Use database lookup tables in AR models.)
11
+ gem.summary = %q(A thread-safe lookup table cache for ActiveRecord)
12
+ gem.description = %q(Use database lookup tables in AR models.)
12
13
 
13
- gem.authors = ["Erik Peterson"]
14
- gem.email = ["erik@enova.com"]
14
+ gem.authors = ["Erik Peterson"]
15
+ gem.email = ["erik@enova.com"]
15
16
 
16
- gem.homepage = "http://www.github.com/companygardener/lookup_by"
17
+ gem.homepage = "https://www.github.com/companygardener/lookup_by"
18
+ gem.license = "MIT"
17
19
 
18
- gem.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
- gem.files = `git ls-files`.split("\n")
20
- gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ gem.files = `git ls-files -z`.split("\x0")
21
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
21
24
 
22
- gem.add_dependency "rails", ">= 3.0.0"
25
+ gem.add_dependency "rails", ">= 3.2.0"
26
+
27
+ gem.add_development_dependency "bundler", "~> 1.3"
28
+ gem.add_development_dependency "rake"
23
29
  end
@@ -1,6 +1,5 @@
1
1
  require "spec_helper"
2
2
  require "lookup_by"
3
- require "pry"
4
3
 
5
4
  describe ::ActiveRecord::Base do
6
5
  describe "macro methods" do
@@ -1,6 +1,8 @@
1
1
  require File.expand_path('../boot', __FILE__)
2
2
 
3
- require "rails/all"
3
+ # require "rails/all"
4
+
5
+ require 'active_record/railtie'
4
6
 
5
7
  # Require the gems listed in Gemfile, including any gems
6
8
  # you've limited to :test, :development, or :production.
@@ -11,19 +11,10 @@ Dummy::Application.configure do
11
11
 
12
12
  # Show full error reports and disable caching.
13
13
  config.consider_all_requests_local = true
14
- config.action_controller.perform_caching = false
15
-
16
- # Don't care if the mailer can't send.
17
- config.action_mailer.raise_delivery_errors = false
18
14
 
19
15
  # Print deprecation notices to the Rails logger.
20
16
  config.active_support.deprecation = :log
21
17
 
22
18
  # Raise an error on page load if there are pending migrations
23
19
  config.active_record.migration_error = :page_load
24
-
25
- # Debug mode disables concatenation and preprocessing of assets.
26
- # This option may cause significant delays in view rendering with a large
27
- # number of complex assets.
28
- config.assets.debug = true
29
20
  end
@@ -11,26 +11,4 @@ Dummy::Application.configure do
11
11
  # just for the purpose of running a single test. If you are using a tool that
12
12
  # preloads Rails for running tests, you may have to set it to true.
13
13
  config.eager_load = false
14
-
15
- # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_assets = true
17
- config.static_cache_control = "public, max-age=3600"
18
-
19
- # Show full error reports and disable caching.
20
- config.consider_all_requests_local = true
21
- config.action_controller.perform_caching = false
22
-
23
- # Raise exceptions instead of rendering exception templates.
24
- config.action_dispatch.show_exceptions = false
25
-
26
- # Disable request forgery protection in test environment.
27
- config.action_controller.allow_forgery_protection = false
28
-
29
- # Tell Action Mailer not to deliver emails to the real world.
30
- # The :test delivery method accumulates sent emails in the
31
- # ActionMailer::Base.deliveries array.
32
- config.action_mailer.delivery_method = :test
33
-
34
- # Print deprecation notices to the stderr.
35
- config.active_support.deprecation = :stderr
36
14
  end
@@ -96,6 +96,31 @@ describe LookupBy::Lookup do
96
96
  it "sets testing when RAILS_ENV=test" do
97
97
  subject.lookup.testing.should be_true
98
98
  end
99
+
100
+ it "does not write primary keys" do
101
+ expect { UserAgent[1] }.to_not raise_error
102
+ end
103
+
104
+ # Has begin..ensure to prevent monkey patch from leaking.
105
+ it "handles the race condition on write-throughs" do
106
+ begin
107
+ class ::LookupBy::Cache
108
+ alias fetch_old fetch
109
+
110
+ def fetch(value)
111
+ db_write(value)
112
+ db_write(value)
113
+ end
114
+ end
115
+
116
+ expect { UserAgent.transaction { UserAgent["Mozilla"].destroy } }.to_not raise_error
117
+ ensure
118
+ class ::LookupBy::Cache
119
+ alias fetch fetch_old
120
+ undef fetch_old
121
+ end
122
+ end
123
+ end
99
124
  end
100
125
 
101
126
  context "IpAddress.lookup_by :column, cache: N, find_or_create: true" do
@@ -0,0 +1,42 @@
1
+ require 'colored'
2
+
3
+ at_exit {
4
+ def gems(files)
5
+ files.map { |path| path[%r{(rubysl-.*)-\d[^/]+/}, 1] }.compact.uniq.sort
6
+ end
7
+
8
+ def gemlist(list)
9
+ puts list.map { |gem| "gem '#{gem}'" }.join("\n")
10
+ end
11
+
12
+ def header(label, list)
13
+ puts
14
+ puts "# [#{list.size}] #{label}".yellow
15
+ end
16
+
17
+ def section(label, files)
18
+ list = gems(files)
19
+
20
+ header label, list
21
+ gemlist list
22
+ end
23
+
24
+ files = $".grep /rubysl/
25
+
26
+ if ENV["DEBUG"] == "2"
27
+ header "Files", files
28
+ puts files.sort.join("\n")
29
+ end
30
+
31
+ runtime = files.grep %r{rubinius-[\d.]+/runtime/gems/}
32
+ internal = files.grep %r{rubinius-[\d.]+/gems/gems/}
33
+ external = files - runtime - internal
34
+ overlap = (gems(external) & gems(runtime)) | (gems(external) & gems(internal))
35
+
36
+ section "Rubinius runtime", runtime
37
+ section "Rubinius internal", internal
38
+ section "Rubygems", external
39
+
40
+ header "Overlapping", overlap
41
+ gemlist overlap
42
+ }
data/spec/spec_helper.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  ENV["RAILS_ENV"] ||= 'test'
3
3
 
4
- GC.disable if defined?(GC) && GC.respond_to?(:disable)
5
-
6
- if ENV["COV"]
4
+ if ENV["COVERAGE"]
7
5
  require "simplecov"
6
+ require 'coveralls'
7
+
8
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ Coveralls::SimpleCov::Formatter,
10
+ SimpleCov::Formatter::HTMLFormatter,
11
+ ]
12
+
8
13
  SimpleCov.start
9
14
  end
10
15
 
@@ -14,27 +19,16 @@ rescue LoadError
14
19
  require File.expand_path("../dummy/config/environment", __FILE__)
15
20
  end
16
21
 
22
+ require 'rspec'
17
23
  require 'database_cleaner'
18
- require 'rspec/rails'
19
- require 'rspec/autorun'
20
24
 
21
25
  # Requires supporting ruby files with custom matchers and macros, etc,
22
26
  # in spec/support/ and its subdirectories.
23
27
  Dir[Rails.root.join("../support/**/*.rb")].each {|f| require f}
24
28
 
25
29
  RSpec.configure do |config|
26
- # ## Mock Framework
27
- #
28
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
29
- #
30
- # config.mock_with :mocha
31
- # config.mock_with :flexmock
32
- # config.mock_with :rr
33
-
34
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
35
- # examples within a transaction, remove the following line or assign false
36
- # instead of true.
37
- config.use_transactional_fixtures = false
30
+ config.backtrace_exclusion_patterns << /vendor\//
31
+ config.backtrace_exclusion_patterns << /lib\/rspec\/rails/
38
32
 
39
33
  # Run specs in random order to surface order dependencies. If you find an
40
34
  # order dependency and want to debug it, you can fix the order by providing
@@ -54,3 +48,5 @@ RSpec.configure do |config|
54
48
  DatabaseCleaner.clean
55
49
  end
56
50
  end
51
+
52
+ require 'rubinius_helper' if ENV["DEBUG"] && RUBY_ENGINE == 'rbx'
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.3.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Peterson
@@ -16,14 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 3.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
27
55
  description: Use database lookup tables in AR models.
28
56
  email:
29
57
  - erik@enova.com
@@ -55,7 +83,6 @@ files:
55
83
  - lookup_by.gemspec
56
84
  - spec/association_spec.rb
57
85
  - spec/caching/lru_spec.rb
58
- - spec/dummy/.rspec
59
86
  - spec/dummy/Rakefile
60
87
  - spec/dummy/app/models/.gitkeep
61
88
  - spec/dummy/app/models/account.rb
@@ -78,17 +105,11 @@ files:
78
105
  - spec/dummy/config/database.yml
79
106
  - spec/dummy/config/environment.rb
80
107
  - spec/dummy/config/environments/development.rb
81
- - spec/dummy/config/environments/production.rb
82
108
  - spec/dummy/config/environments/test.rb
83
109
  - spec/dummy/config/initializers/backtrace_silencers.rb
84
110
  - spec/dummy/config/initializers/filter_parameter_logging.rb
85
111
  - spec/dummy/config/initializers/inflections.rb
86
- - spec/dummy/config/initializers/mime_types.rb
87
- - spec/dummy/config/initializers/secret_token.rb
88
- - spec/dummy/config/initializers/session_store.rb
89
- - spec/dummy/config/initializers/wrap_parameters.rb
90
112
  - spec/dummy/config/locales/en.yml
91
- - spec/dummy/config/routes.rb
92
113
  - spec/dummy/db/migrate/20121019040009_create_tables.rb
93
114
  - spec/dummy/db/seeds.rb
94
115
  - spec/dummy/db/structure.sql
@@ -96,10 +117,12 @@ files:
96
117
  - spec/dummy/log/.gitkeep
97
118
  - spec/dummy/script/rails
98
119
  - spec/lookup_by_spec.rb
120
+ - spec/rubinius_helper.rb
99
121
  - spec/spec_helper.rb
100
122
  - spec/support/shared_examples_for_a_lookup.rb
101
- homepage: http://www.github.com/companygardener/lookup_by
102
- licenses: []
123
+ homepage: https://www.github.com/companygardener/lookup_by
124
+ licenses:
125
+ - MIT
103
126
  metadata: {}
104
127
  post_install_message:
105
128
  rdoc_options: []
@@ -124,7 +147,6 @@ summary: A thread-safe lookup table cache for ActiveRecord
124
147
  test_files:
125
148
  - spec/association_spec.rb
126
149
  - spec/caching/lru_spec.rb
127
- - spec/dummy/.rspec
128
150
  - spec/dummy/Rakefile
129
151
  - spec/dummy/app/models/.gitkeep
130
152
  - spec/dummy/app/models/account.rb
@@ -147,17 +169,11 @@ test_files:
147
169
  - spec/dummy/config/database.yml
148
170
  - spec/dummy/config/environment.rb
149
171
  - spec/dummy/config/environments/development.rb
150
- - spec/dummy/config/environments/production.rb
151
172
  - spec/dummy/config/environments/test.rb
152
173
  - spec/dummy/config/initializers/backtrace_silencers.rb
153
174
  - spec/dummy/config/initializers/filter_parameter_logging.rb
154
175
  - spec/dummy/config/initializers/inflections.rb
155
- - spec/dummy/config/initializers/mime_types.rb
156
- - spec/dummy/config/initializers/secret_token.rb
157
- - spec/dummy/config/initializers/session_store.rb
158
- - spec/dummy/config/initializers/wrap_parameters.rb
159
176
  - spec/dummy/config/locales/en.yml
160
- - spec/dummy/config/routes.rb
161
177
  - spec/dummy/db/migrate/20121019040009_create_tables.rb
162
178
  - spec/dummy/db/seeds.rb
163
179
  - spec/dummy/db/structure.sql
@@ -165,5 +181,6 @@ test_files:
165
181
  - spec/dummy/log/.gitkeep
166
182
  - spec/dummy/script/rails
167
183
  - spec/lookup_by_spec.rb
184
+ - spec/rubinius_helper.rb
168
185
  - spec/spec_helper.rb
169
186
  - spec/support/shared_examples_for_a_lookup.rb
data/spec/dummy/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,80 +0,0 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb.
3
-
4
- # Code is not reloaded between requests.
5
- config.cache_classes = true
6
-
7
- # Eager load code on boot. This eager loads most of Rails and
8
- # your application in memory, allowing both thread web servers
9
- # and those relying on copy on write to perform better.
10
- # Rake tasks automatically ignore this option for performance.
11
- config.eager_load = true
12
-
13
- # Full error reports are disabled and caching is turned on.
14
- config.consider_all_requests_local = false
15
- config.action_controller.perform_caching = true
16
-
17
- # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
- # Add `rack-cache` to your Gemfile before enabling this.
19
- # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
- # config.action_dispatch.rack_cache = true
21
-
22
- # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_assets = false
24
-
25
- # Compress JavaScripts and CSS.
26
- config.assets.js_compressor = :uglifier
27
- # config.assets.css_compressor = :sass
28
-
29
- # Do not fallback to assets pipeline if a precompiled asset is missed.
30
- config.assets.compile = false
31
-
32
- # Generate digests for assets URLs.
33
- config.assets.digest = true
34
-
35
- # Version of your assets, change this if you want to expire all your assets.
36
- config.assets.version = '1.0'
37
-
38
- # Specifies the header that your server uses for sending files.
39
- # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
40
- # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
41
-
42
- # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
43
- # config.force_ssl = true
44
-
45
- # Set to :debug to see everything in the log.
46
- config.log_level = :info
47
-
48
- # Prepend all log lines with the following tags.
49
- # config.log_tags = [ :subdomain, :uuid ]
50
-
51
- # Use a different logger for distributed setups.
52
- # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53
-
54
- # Use a different cache store in production.
55
- # config.cache_store = :mem_cache_store
56
-
57
- # Enable serving of images, stylesheets, and JavaScripts from an asset server.
58
- # config.action_controller.asset_host = "http://assets.example.com"
59
-
60
- # Precompile additional assets.
61
- # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
62
- # config.assets.precompile += %w( search.js )
63
-
64
- # Ignore bad email addresses and do not raise email delivery errors.
65
- # Set this to true and configure the email server for immediate delivery to raise delivery errors.
66
- # config.action_mailer.raise_delivery_errors = false
67
-
68
- # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
69
- # the I18n.default_locale when a translation can not be found).
70
- config.i18n.fallbacks = true
71
-
72
- # Send deprecation notices to registered listeners.
73
- config.active_support.deprecation = :notify
74
-
75
- # Disable automatic flushing of the log to improve performance.
76
- # config.autoflush_log = false
77
-
78
- # Use default logging formatter so that PID and timestamp are not suppressed.
79
- config.log_formatter = ::Logger::Formatter.new
80
- end
@@ -1,5 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
5
- # Mime::Type.register_alias "text/html", :iphone
@@ -1,12 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # Your secret key is used for verifying the integrity of signed cookies.
4
- # If you change this key, all old signed cookies will become invalid!
5
-
6
- # Make sure the secret is at least 30 characters and all random,
7
- # no regular words or you'll be exposed to dictionary attacks.
8
- # You can use `rake secret` to generate a secure secret key.
9
-
10
- # Make sure your secret_key_base is kept private
11
- # if you're sharing your code publicly.
12
- Dummy::Application.config.secret_key_base = 'dd1f177df9ee969a1650a95ccd09916cd7df6779d28eb863b5ab89f5635e9ee69a1394a79628e3ca005b2333a1419a3e1c17f1086179d48a8a6f6ff6ac3d6bec'
@@ -1,3 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- Dummy::Application.config.session_store :cookie_store, key: '_dummy_session'
@@ -1,14 +0,0 @@
1
- # Be sure to restart your server when you modify this file.
2
-
3
- # This file contains settings for ActionController::ParamsWrapper which
4
- # is enabled by default.
5
-
6
- # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7
- ActiveSupport.on_load(:action_controller) do
8
- wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9
- end
10
-
11
- # To enable root element in JSON for ActiveRecord objects.
12
- # ActiveSupport.on_load(:active_record) do
13
- # self.include_root_in_json = true
14
- # end
@@ -1,56 +0,0 @@
1
- Dummy::Application.routes.draw do
2
- # The priority is based upon order of creation: first created -> highest priority.
3
- # See how all your routes lay out with "rake routes".
4
-
5
- # You can have the root of your site routed with "root"
6
- # root 'welcome#index'
7
-
8
- # Example of regular route:
9
- # get 'products/:id' => 'catalog#view'
10
-
11
- # Example of named route that can be invoked with purchase_url(id: product.id)
12
- # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
13
-
14
- # Example resource route (maps HTTP verbs to controller actions automatically):
15
- # resources :products
16
-
17
- # Example resource route with options:
18
- # resources :products do
19
- # member do
20
- # get 'short'
21
- # post 'toggle'
22
- # end
23
- #
24
- # collection do
25
- # get 'sold'
26
- # end
27
- # end
28
-
29
- # Example resource route with sub-resources:
30
- # resources :products do
31
- # resources :comments, :sales
32
- # resource :seller
33
- # end
34
-
35
- # Example resource route with more complex sub-resources:
36
- # resources :products do
37
- # resources :comments
38
- # resources :sales do
39
- # get 'recent', on: :collection
40
- # end
41
- # end
42
-
43
- # Example resource route with concerns:
44
- # concern :toggleable do
45
- # post 'toggle'
46
- # end
47
- # resources :posts, concerns: :toggleable
48
- # resources :photos, concerns: :toggleable
49
-
50
- # Example resource route within a namespace:
51
- # namespace :admin do
52
- # # Directs /admin/products/* to Admin::ProductsController
53
- # # (app/controllers/admin/products_controller.rb)
54
- # resources :products
55
- # end
56
- end