usa 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +1 -1
- data/lib/usa/engine.rb +1 -6
- data/lib/usa/version.rb +1 -1
- data/lib/usa.rb +15 -9
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 548ccad376f01003a206b1c4a9691fac0beba122f699b3215171aff74ad7bc6f
|
|
4
|
+
data.tar.gz: dc17540f0361f124ae91a6af8888c3af063cf290416e7abb9cc39e7a852548f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fda77e35c1d90e41334f16203e7156ce1739b50a1fba3bab650ab894ce853c171d0054745736f77b1dea45afd6936b4886ed47ff33c7da5e0ad67e42adacf44f
|
|
7
|
+
data.tar.gz: 025b0c17a446ec5da6f19e6821e5c93e0ae3f9ecccc0d99bbc7198b6efd33df0e819bafb6a6e1f6f634e275cd7874ae7539c25b9a5660167d0ad04f2efd5719b
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,16 @@ For more information about changelogs, check [Keep a Changelog](http://keepachan
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## 0.4.2 - 2026-09-16
|
|
11
|
+
|
|
12
|
+
* [Fix] The check that refuses a host's own class where one of these models should be asks the
|
|
13
|
+
files rather than the constants, and loads nothing to answer. 0.4.1 moved it onto
|
|
14
|
+
`ActiveSupport.on_load(:active_record)`, which fires long before an app is ready: a host whose
|
|
15
|
+
own load hook declares `belongs_to :market, counter_cache: true` had that class name resolved
|
|
16
|
+
on the spot, which reached `ApplicationRecord` before the database was configured and stopped
|
|
17
|
+
the boot. Zeitwerk is asked which directory holds a `city.rb` instead, which answers the same
|
|
18
|
+
question without loading a model or Active Record behind it
|
|
19
|
+
|
|
10
20
|
## 0.4.1 - 2026-09-16
|
|
11
21
|
|
|
12
22
|
* [Fix] The check that refuses a host's own class where one of these models should be is asked
|
data/README.md
CHANGED
|
@@ -12,7 +12,7 @@ To install on your system, run
|
|
|
12
12
|
|
|
13
13
|
To use inside a bundled Ruby project, add this line to the `Gemfile`:
|
|
14
14
|
|
|
15
|
-
gem 'usa', '~> 0.4.
|
|
15
|
+
gem 'usa', '~> 0.4.2'
|
|
16
16
|
|
|
17
17
|
Below 1.0 the pin stops at the next minor rather than the next major, because that is where a
|
|
18
18
|
breaking change may still land. It becomes `~> 1.0` once the API is settled on purpose.
|
data/lib/usa/engine.rb
CHANGED
|
@@ -4,11 +4,6 @@ require 'rails/engine'
|
|
|
4
4
|
module USA
|
|
5
5
|
# Teaches Rails where this gem's models live, and refuses a host that has taken their names.
|
|
6
6
|
class Engine < ::Rails::Engine
|
|
7
|
-
|
|
8
|
-
# models pulls Active Record in behind them, and pulling it in before initialization is
|
|
9
|
-
# over slows every boot and can reorder a host's own -- which is what Rails warns about.
|
|
10
|
-
ActiveSupport.on_load(:active_record) do
|
|
11
|
-
USA.verify_models ::State, ::County, ::City, ::CityCounty, ::ZIP
|
|
12
|
-
end
|
|
7
|
+
config.to_prepare { USA.verify_models }
|
|
13
8
|
end
|
|
14
9
|
end
|
data/lib/usa/version.rb
CHANGED
data/lib/usa.rb
CHANGED
|
@@ -34,18 +34,24 @@ module USA
|
|
|
34
34
|
County.recount_zips
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
# The file each of this gem's models is defined in, which is the name a host must not take.
|
|
38
|
+
MODELS = %w[city city_county county state zip]
|
|
39
|
+
|
|
37
40
|
# Refuses a host's own class standing where one of this gem's models should be. Zeitwerk
|
|
38
41
|
# gives an app's file precedence over an engine's, silently, so without this a host holding
|
|
39
42
|
# `app/models/city.rb` would find every association of this gem's pointing at a class of its
|
|
40
|
-
# own.
|
|
41
|
-
#
|
|
43
|
+
# own. Asked of the files rather than of the constants: loading a model to find out pulls
|
|
44
|
+
# Active Record in with it, long before an app is ready for either.
|
|
45
|
+
# @param [Array<String>] dirs the autoloaded directories to look through.
|
|
42
46
|
# @return [void]
|
|
43
|
-
def self.verify_models(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
def self.verify_models(dirs = Rails.autoloaders.main.dirs)
|
|
48
|
+
mine = Engine.root.join('app/models').to_s
|
|
49
|
+
taken = dirs.reject { |dir| dir == mine }.
|
|
50
|
+
flat_map { |dir| MODELS.select { |model| File.exist? File.join(dir, "#{model}.rb") } }
|
|
51
|
+
return if taken.empty?
|
|
52
|
+
|
|
53
|
+
raise Error, "The usa gem defines #{taken.uniq.map(&:camelize).to_sentence}, and a file " \
|
|
54
|
+
'of your own takes the name first. Rename yours: Rails gives an app’s file precedence ' \
|
|
55
|
+
'over an engine’s, silently, and the models this gem ships would point at your class.'
|
|
50
56
|
end
|
|
51
57
|
end
|