usa 0.1.0

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.
@@ -0,0 +1,26 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module USA
4
+ module Generators
5
+ # Everything installing this gem writes into a host: the migrations that make its tables
6
+ # and fill them. Not an initializer, because there is nothing here to configure.
7
+ class InstallGenerator < Rails::Generators::Base
8
+ include ActiveRecord::Generators::Migration
9
+
10
+ # Thor reads `USA` as `u_s_a` rather than underscoring it, so the name somebody types is
11
+ # said here. Without this line `bin/rails g usa:install` finds no generator at all.
12
+ namespace 'usa:install'
13
+
14
+ # @return [Array<String>] where a file being copied is looked for.
15
+ def self.source_paths = [ USA::Engine.root.join('db/migrate').to_s ]
16
+
17
+ # Copied rather than read off the gem, so the host owns the files and their timestamps.
18
+ # @return [void]
19
+ def copy_migrations
20
+ Dir.children(USA::Engine.root.join('db/migrate')).sort.each do |name|
21
+ migration_template name, "db/migrate/#{name.split('_', 2).last}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ namespace :db do
2
+ namespace :usa do
3
+ desc 'Write every state, county, city and ZIP, including the ones a release has added'
4
+ task seed: :environment do
5
+ USA.seed
6
+ end
7
+ end
8
+ end
data/lib/usa/engine.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'action_dispatch'
2
+ require 'rails/engine'
3
+
4
+ module USA
5
+ # Teaches Rails where this gem's models live, and prefixes their tables with `usa_`.
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace USA
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module USA
2
+ # The version of this gem, as RubyGems knows it.
3
+ VERSION = '0.1.0'
4
+ end
data/lib/usa.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'active_support/inflector'
2
+ require 'csv'
3
+
4
+ # Before the engine, so Zeitwerk reads usa/zip.rb as USA::ZIP and a heading says ZIP, not Zip.
5
+ ActiveSupport::Inflector.inflections do |inflect|
6
+ inflect.acronym 'USA'
7
+ inflect.acronym 'ZIP'
8
+ inflect.acronym 'FIPS'
9
+ end
10
+
11
+ require 'usa/version'
12
+ require 'usa/engine'
13
+
14
+ # The geography of the United States: the states, counties, cities and ZIPs an address names.
15
+ module USA
16
+ # Writes every row this release holds, keeping the id of every row the database already has.
17
+ # @return [void]
18
+ def self.seed
19
+ [ USA::State, USA::County, USA::City, USA::CityCounty, USA::ZIP ].each(&:seed)
20
+ USA::State.recount_counties
21
+ USA::County.recount_zips
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: usa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Baccigalupo
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: csv
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rails
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ description: Every state, county, city and ZIP, as tables a Rails app joins to
41
+ email:
42
+ - claudiob@users.noreply.github.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - CHANGELOG.md
48
+ - LICENSE.txt
49
+ - README.md
50
+ - app/models/concerns/usa/seeded.rb
51
+ - app/models/usa/city.rb
52
+ - app/models/usa/city_county.rb
53
+ - app/models/usa/county.rb
54
+ - app/models/usa/record.rb
55
+ - app/models/usa/state.rb
56
+ - app/models/usa/zip.rb
57
+ - db/migrate/20260914120000_create_usa_states.rb
58
+ - db/migrate/20260914120001_create_usa_counties.rb
59
+ - db/migrate/20260914120002_create_usa_zips.rb
60
+ - db/migrate/20260914120003_create_usa_cities.rb
61
+ - db/migrate/20260914120004_create_usa_city_counties.rb
62
+ - db/migrate/20260914120005_seed_usa.rb
63
+ - db/seeds/cities.csv
64
+ - db/seeds/counties.csv
65
+ - db/seeds/states.csv
66
+ - db/seeds/zips.csv
67
+ - lib/generators/usa/install/install_generator.rb
68
+ - lib/tasks/usa.rake
69
+ - lib/usa.rb
70
+ - lib/usa/engine.rb
71
+ - lib/usa/version.rb
72
+ homepage: https://github.com/claudiob/usa
73
+ licenses:
74
+ - MIT
75
+ metadata:
76
+ homepage_uri: https://github.com/claudiob/usa
77
+ source_code_uri: https://github.com/claudiob/usa/
78
+ changelog_uri: https://github.com/claudiob/usa/blob/main/CHANGELOG.md
79
+ documentation_uri: https://rubydoc.info/gems/usa
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 3.2.0
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 4.0.3
95
+ specification_version: 4
96
+ summary: The geography of the United States
97
+ test_files: []