geopolitical 3.0.0 → 3.2.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.
Files changed (108) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +28 -0
  3. data/README.md +152 -73
  4. data/app/controllers/geopolitical/application_controller.rb +8 -0
  5. data/app/controllers/geopolitical/cities_controller.rb +57 -0
  6. data/app/controllers/geopolitical/geopolitical_controller.rb +19 -0
  7. data/app/controllers/geopolitical/hoods_controller.rb +56 -0
  8. data/app/controllers/geopolitical/nations_controller.rb +51 -0
  9. data/app/controllers/geopolitical/regions_controller.rb +56 -0
  10. data/app/helpers/geopolitical/application_helper.rb +2 -0
  11. data/app/models/city.rb +149 -48
  12. data/app/models/concerns/geopolitocracy.rb +121 -34
  13. data/app/models/hood.rb +44 -18
  14. data/app/models/nation.rb +96 -17
  15. data/app/models/region.rb +42 -14
  16. data/app/views/geopolitical/cities/_city.html.haml +2 -5
  17. data/app/views/geopolitical/cities/_form.html.haml +25 -28
  18. data/app/views/geopolitical/cities/edit.html.haml +1 -0
  19. data/app/views/geopolitical/cities/index.html.haml +17 -20
  20. data/app/views/geopolitical/cities/new.html.haml +1 -0
  21. data/app/views/geopolitical/cities/show.html.haml +7 -7
  22. data/app/views/geopolitical/geopolitical/index.html.haml +7 -9
  23. data/app/views/geopolitical/hoods/_city.html.haml +2 -5
  24. data/app/views/geopolitical/hoods/_form.html.haml +21 -22
  25. data/app/views/geopolitical/hoods/edit.html.haml +1 -0
  26. data/app/views/geopolitical/hoods/index.html.haml +13 -18
  27. data/app/views/geopolitical/hoods/new.html.haml +1 -0
  28. data/app/views/geopolitical/hoods/show.html.haml +5 -5
  29. data/app/views/geopolitical/nations/_form.html.haml +11 -8
  30. data/app/views/geopolitical/nations/_nation.html.haml +5 -0
  31. data/app/views/geopolitical/nations/edit.html.haml +1 -0
  32. data/app/views/geopolitical/nations/index.html.haml +16 -20
  33. data/app/views/geopolitical/nations/new.html.haml +1 -0
  34. data/app/views/geopolitical/nations/show.html.haml +7 -7
  35. data/app/views/geopolitical/regions/_form.html.haml +10 -8
  36. data/app/views/geopolitical/regions/_region.html.haml +2 -5
  37. data/app/views/geopolitical/regions/edit.html.haml +1 -0
  38. data/app/views/geopolitical/regions/index.html.haml +12 -15
  39. data/app/views/geopolitical/regions/new.html.haml +1 -0
  40. data/app/views/geopolitical/regions/show.html.haml +5 -5
  41. data/app/views/layouts/geopolitical.html.haml +13 -15
  42. data/config/locales/geopolitical.en.yml +76 -0
  43. data/config/locales/geopolitical.pt.yml +77 -0
  44. data/geopolitical.gemspec +14 -12
  45. data/lib/geopolitical/engine.rb +3 -0
  46. data/lib/geopolitical/version.rb +3 -2
  47. data/lib/geopolitical.rb +23 -3
  48. metadata +47 -118
  49. data/.coveralls.yml +0 -1
  50. data/.gitignore +0 -11
  51. data/.rspec +0 -1
  52. data/.travis.yml +0 -26
  53. data/Gemfile +0 -15
  54. data/Guardfile +0 -24
  55. data/Rakefile +0 -25
  56. data/app/serializers/city_serializer.rb +0 -8
  57. data/app/serializers/nation_serializer.rb +0 -4
  58. data/app/serializers/region_serializer.rb +0 -4
  59. data/bin/rails +0 -8
  60. data/lib/tasks/geopolitical_tasks.rake +0 -4
  61. data/spec/dummy/README.rdoc +0 -28
  62. data/spec/dummy/Rakefile +0 -6
  63. data/spec/dummy/app/assets/images/.keep +0 -0
  64. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  65. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  66. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  67. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  68. data/spec/dummy/app/mailers/.keep +0 -0
  69. data/spec/dummy/app/models/.keep +0 -0
  70. data/spec/dummy/app/models/concerns/.keep +0 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  72. data/spec/dummy/bin/bundle +0 -3
  73. data/spec/dummy/bin/rails +0 -4
  74. data/spec/dummy/bin/rake +0 -4
  75. data/spec/dummy/config/application.rb +0 -27
  76. data/spec/dummy/config/boot.rb +0 -5
  77. data/spec/dummy/config/environment.rb +0 -5
  78. data/spec/dummy/config/environments/development.rb +0 -29
  79. data/spec/dummy/config/environments/production.rb +0 -80
  80. data/spec/dummy/config/environments/test.rb +0 -36
  81. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  82. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  83. data/spec/dummy/config/initializers/inflections.rb +0 -16
  84. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  85. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  86. data/spec/dummy/config/initializers/session_store.rb +0 -3
  87. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  88. data/spec/dummy/config/locales/en.yml +0 -23
  89. data/spec/dummy/config/mongoid.yml +0 -63
  90. data/spec/dummy/config/routes.rb +0 -56
  91. data/spec/dummy/config.ru +0 -4
  92. data/spec/dummy/lib/assets/.keep +0 -0
  93. data/spec/dummy/log/.keep +0 -0
  94. data/spec/dummy/log/development.log +0 -0
  95. data/spec/dummy/log/test.log +0 -23532
  96. data/spec/dummy/public/404.html +0 -58
  97. data/spec/dummy/public/422.html +0 -58
  98. data/spec/dummy/public/500.html +0 -57
  99. data/spec/dummy/public/favicon.ico +0 -0
  100. data/spec/fabricators/city_fabricator.rb +0 -6
  101. data/spec/fabricators/hood_fabricator.rb +0 -5
  102. data/spec/fabricators/nation_fabricator.rb +0 -4
  103. data/spec/fabricators/region_fabricator.rb +0 -5
  104. data/spec/models/city_spec.rb +0 -158
  105. data/spec/models/hood_spec.rb +0 -47
  106. data/spec/models/nation_spec.rb +0 -53
  107. data/spec/models/region_spec.rb +0 -20
  108. data/spec/spec_helper.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8e48641bb3edaca229ec8ee388684cff45da3612
4
- data.tar.gz: 1cf9b43ae4f9080148b6bbd12f0ffaf0602d48d4
2
+ SHA256:
3
+ metadata.gz: 6eab76b546c1fe68a2b74c24193504f349c650ef97a5982cc87ee5fb74769d4e
4
+ data.tar.gz: 3301e6d264d6446a0663941819b76b64f956e83f89a16e5bcf70f87644abe616
5
5
  SHA512:
6
- metadata.gz: 75ec8c8ae0d7e35033e6ce0274f37c0e2b543bdca5d4e100dd97eb0bb758d761de58c24c0f2f823c88e73146e26eedb5df938987a42939276c88d940cf2e7145
7
- data.tar.gz: 8fa9fb4416f4a07b42a4c9f17c3a2986d7650727c4dbdab898e60ea4570c1e5261de3aa782296848f441bd94cd55d80dd44ffba6bc654f24daf866b65f3175a2
6
+ metadata.gz: e4b582dacaf75fe5584450b61ee55d05bab5e15565ee7ee31c0104a852fcd1d28853fef45aa11c5de67bc48d9be8f18997789032fed639dd4deba8a5cd8e45ad
7
+ data.tar.gz: 1461b8bf452628a21c708f7c884d72301d0ac421079671b554e1aa2d4816064adafde8595c95c988936b52f85b5996c37bd27e08c00ee8e1d31461f88c200e68
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ ## 3.2.0
4
+
5
+ - Slugs work in every script: `東京` → `東京`, `Санкт-Петербург` → `санкт-петербург`. Non-Latin names were previously invalid (blank slug). Accents are stripped via NFKD (`Hà Nội` → `ha-noi`). Underscores now become hyphens.
6
+ - `Geopolitocracy.slugify(text)` is public; `slug=`, `.search` and `Hood` all use it.
7
+ - `Nation['br']` — find by abbr, any case.
8
+ - City name uniqueness is now scoped by nation **and** region; region-less cities in different nations no longer collide.
9
+ - Removed `==`/`<=>` overrides on City, Region, Hood (Mongoid's `_id` equality already matches the unique indexes) and `Hood#as_json`.
10
+ - Removed empty rake task and RDoc task.
11
+ - Tested on Ruby 3.2 through 4.0 (CI matrix); `required_ruby_version` is now `>= 3.2` (Rails 8 / the test suite floor).
12
+ - Engine request specs cover full CRUD for all four resources.
13
+ - `Geopolitical.parent_controller` lets a host app point the engine's controllers at one of its own, so the admin UI inherits the host's authentication. Defaults to `ActionController::Base` (unauthenticated), and the README now says so.
14
+ - **i18n**: every label, button, table header and flash in the engine now goes through `I18n`; `config/locales/geopolitical.en.yml` and `geopolitical.pt.yml` ship with the gem. Model and attribute names use Mongoid's `mongoid.models` / `mongoid.attributes` scopes, so `f.label :souls` translates for free.
15
+ - The dashboard and layout used `model_name.human.pluralize` for nav headings, which is English-only ("Regiãos"); they now use `model_name.human(count: 2)`.
16
+
17
+ ### Fixes from review
18
+
19
+
20
+ - **City slugs are unique planet-wide again.** A city with no region is now suffixed with its nation abbr (`singapore-sg`, `victoria-sc`), mirroring the region suffix (`santos-sp`). Previously two region-less cities in different nations both slugged to the same string.
21
+ - `City`s unique slug index was never created: `Geopolitocracy` declared a plain `index({slug: 1})` that shadowed it. The concern no longer declares one; `Region` (which needs a non-unique one for `.search`) declares its own.
22
+ - `slugify` normalizes to NFC first — decomposed input (macOS filenames, some form posts) slugged as `sa-o-paulo`.
23
+ - Moving a city to another region now refreshes the cached `rbbr` and rebuilds the slug; it used to keep the old abbr forever.
24
+ - Renaming or moving a `Hood` rebuilds its slug instead of stacking prefixes (`rio-rj-santos-sp-gonzaga`).
25
+ - `Nation#lang=` keeps the nations other languages instead of wiping `langs` to a single entry.
26
+ - `Nation[]` returns `nil` for an unknown abbr instead of raising `DocumentNotFound`.
27
+
28
+ **Upgrading:** stored slugs are not rewritten until a document is saved again, so existing data is untouched � but region-less cities will pick up a nation suffix the next time they are saved, and `City.create_indexes` will now fail on a database that already holds duplicate city slugs. `geonames_local` depends on `geopolitical > 0.8.4` (no upper bound) and will pick this up on its next bundle.
data/README.md CHANGED
@@ -1,91 +1,170 @@
1
- Geopolitical
2
- ============
1
+ # Geopolitical
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/geopolitical.svg)](http://badge.fury.io/rb/geopolitical)
5
- [![Code Climate](https://codeclimate.com/github/fireho/geopolitical.svg)](https://codeclimate.com/github/fireho/geopolitical)
6
- [![Coverage Status](https://coveralls.io/repos/fireho/geopolitical/badge.svg?branch=&service=github)](https://coveralls.io/github/fireho/geopolitical?branch=)
7
- [![Dependency Status](https://gemnasium.com/fireho/geopolitical.svg)](https://gemnasium.com/fireho/geopolitical)
8
- [![Build Status](https://travis-ci.org/fireho/geopolitical.svg)](https://travis-ci.org/fireho/geopolitical)
4
+ [![CI](https://github.com/fireho/geopolitical/actions/workflows/ci.yml/badge.svg)](https://github.com/fireho/geopolitical/actions/workflows/ci.yml)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](MIT-LICENSE)
6
+
7
+ ```
8
+ _.--""--._ Nation ─┐ "Brasil" BR .br BRL +55
9
+ .' __ o '. │
10
+ / .' \ \ Region ─┤ "São Paulo" SP America/Sao_Paulo
11
+ | / o | ~ | │
12
+ | \_ o / ~ | City ─┤ "São Paulo" sao-paulo-sp (-46.63, -23.55)
13
+ \ `-' ~ / │
14
+ '. ~ ~ ~ .' Hood ─┘ "Vila Madalena" sao-paulo-sp-vila-madalena
15
+ `--....--'
16
+ place.hood.city.region.nation.planet # => :earth
17
+ ```
18
+
19
+ **The whole planet as four Mongoid models.** Nation → Region → City → Hood,
20
+ with slugs that never collide, names in every script, geo queries, and a
21
+ fallback chain for phone/postal codes. Bring your own data (Geonames, IBGE,
22
+ a CSV, a hunch) — or let [geonames_local](https://github.com/nofxx/geonames_local)
23
+ fill it for you.
24
+
25
+ ## Why not the other gems?
26
+
27
+ | gem | Nation | Region | City | Hood | DB | Geo | i18n names | Admin UI |
28
+ |------------------------------------------------------------|:------:|:------:|:----:|:----:|----------|:---:|:----------:|:--------:|
29
+ | [countries](https://github.com/countries/countries) | ✓ | ✓ | – | – | in-memory| – | ✓ | – |
30
+ | [city-state](https://github.com/loureirorg/city-state) | ✓ | ✓ | ✓ | – | in-memory| – | – | – |
31
+ | [geonames-rails](https://github.com/tanguyantoine/geonames-rails) | ✓ | ✓ | ✓ | – | AR | ✓ | – | – |
32
+ | [geonames_dump](https://github.com/kmmndr/geonames_dump) | ✓ | ✓ | ✓ | – | AR | ✓ | – | – |
33
+ | **geopolitical** | ✓ | ✓ | ✓ | ✓ | Mongoid | ✓ | ✓ | ✓ |
34
+
35
+ Static lists are great until a user wants *their* city in the dropdown, a
36
+ neighborhood on the address, or a query like "cities within 50km".
37
+ That's when you want documents, not constants.
38
+
39
+ ## Install
40
+
41
+ ```ruby
42
+ gem 'geopolitical'
43
+ ```
44
+
45
+ Rails: it's an engine, models autoload. Optionally mount the admin UI:
46
+
47
+ ```ruby
48
+ # config/routes.rb
49
+ mount Geopolitical::Engine => '/geopolitical'
50
+ ```
51
+
52
+ **The admin UI has no authentication of its own** — it is a mountable engine, so
53
+ guarding it is the host app's job. Either constrain the mount:
54
+
55
+ ```ruby
56
+ authenticate :user, ->(user) { user.admin? } do
57
+ mount Geopolitical::Engine => '/geopolitical'
58
+ end
59
+ ```
60
+
61
+ or hand the engine a controller of yours that already authenticates:
62
+
63
+ ```ruby
64
+ # config/initializers/geopolitical.rb
65
+ Geopolitical.parent_controller = 'Admin::BaseController'
66
+ ```
67
+
68
+ Plain Ruby: configure Mongoid, then `require 'geopolitical'`.
69
+
70
+ ### Languages
71
+
72
+ The engine ships `en` and `pt` (`config/locales/geopolitical.*.yml`) and follows
73
+ `I18n.locale` — model names, attribute labels, buttons and flashes all move together:
74
+
75
+ ```ruby
76
+ I18n.locale = :pt
77
+ City.model_name.human(count: 2) # => "Cidades"
78
+ Hood.human_attribute_name(:souls) # => "População"
79
+ ```
80
+
81
+ Override a string by defining the same key in your app, or add a locale by copying
82
+ one of those two files. Note the model *data* is localized separately — `name` and
83
+ `alt` are `localize: true` fields, so a city carries its own name per language.
84
+
85
+ ## Cheat sheet
86
+
87
+
88
+ ```ruby
89
+ br = Nation.create!(name: 'Brasil', abbr: 'br', tld: '.br', cash: 'BRL', langs: %w[pt], phone: '55')
90
+ sp = Region.create!(name: 'São Paulo', abbr: 'SP', nation: br, timezone: 'America/Sao_Paulo')
91
+ sampa = City.create!(name: 'São Paulo', region: sp, souls: 12_000_000, geom: [-46.63, -23.55])
92
+ vila = Hood.create!(name: 'Vila Madalena', city: sampa)
93
+
94
+ Nation['br'] # => #<Nation BR> abbr is the _id, any case
95
+ Nation.find('BR') # same thing
96
+ sampa.slug # => "sao-paulo-sp" region suffix, no collisions
97
+ vila.slug # => "sao-paulo-sp-vila-madalena"
98
+ sampa.nation # => BR derived from the region, you may omit it
99
+ sampa.to_s # => "São Paulo/SP"
100
+ sampa.with_nation('-') # => "São Paulo-SP-BR"
101
+ sampa.population # => 12000000 alias of `souls`
102
+ vila.phone # => "55" hood → city → region → nation
103
+ br.currency # => "BRL" alias of `cash`
104
+
105
+ City.search('sao pa') # slug prefix, accent/case-insensitive
106
+ City.search('sao-paulo-sp', exact: true)
107
+ City.nearby(sampa.geom) # 2dsphere $near, needs City.create_indexes
108
+ City.population.first # biggest city
109
+ Region.ordered # by name
110
+ ```
111
+
112
+ Slugs are the API. They're stable, unique, URL-safe and they survive scripts
113
+ you can't transliterate:
9
114
 
10
- Geopolitical models ready to use!
115
+ ```
116
+ "São Paulo" => "sao-paulo"
117
+ "Baden-Württemberg"=> "baden-wurttemberg"
118
+ "Hà Nội" => "ha-noi"
119
+ "St. Louis" => "st-louis"
120
+ "東京" => "東京"
121
+ "Санкт-Петербург" => "санкт-петербург"
122
+ "دبي" => "دبي"
123
+ ```
11
124
 
12
- With
13
- ----
125
+ Two Springfields? `springfield-il` and `springfield-ma`. Tokyo with a region
126
+ that has no abbr? `tokyo-東京都`. It just works.
14
127
 
15
- gem "geopolitical"
128
+ ## The models
16
129
 
130
+ ```
131
+ Nation _id = abbr (ISO 3166-1 α2) gid tld cash code3 langs capital
132
+ └── Region abbr (ISO 3166-2) code timezone capital unique per nation
133
+ └── City geom (Point) area rbbr slug unique globally
134
+ └── Hood rank slug unique globally
135
+ ```
17
136
 
18
- I have
19
- ------
137
+ Every model shares (via the `Geopolitocracy` concern):
138
+ `name` & `alt` (localized), `abbr`, `nick`, `ascii`, `code`, `slug`,
139
+ `souls`/`population`, `postal`, `phone`, `.search`, `.ordered`, `to_s`, `==`, `<=>`.
20
140
 
21
- [DB Pattern](http://dbpatterns.com/documents/54b5b9529785db781af57b4e)
141
+ Names get titleized only when you shout or mumble: `'new york'` and
142
+ `'NEW YORK'` become `"New York"`; `'McAllen'` stays `"McAllen"`.
22
143
 
23
- Nation > Region > City > Hood all with:
144
+ ## Feeding it
24
145
 
25
- * Names (with i18n and sanitized version)
26
- * ISO codes and abbreviations (Nations & Regions)
27
- * Hierarchy (Hood.first.city.region.nation.abbr # BR)
28
- * Languages
29
- * Geometries
30
- * Postal codes
31
- * Phone codes
146
+ [geonames_local](https://github.com/nofxx/geonames_local) downloads
147
+ [Geonames](http://download.geonames.org/export/dump/) dumps and writes
148
+ straight into these models:
32
149
 
150
+ ```
151
+ geonames BR -c geonames.yml # all of Brasil: regions, cities, hoods
152
+ ```
33
153
 
34
- Geopolitical
35
- ------------
154
+ Or hand-roll from any source — every model is just a Mongoid document.
36
155
 
37
- ## ISO 3366-1
156
+ ## Development
38
157
 
39
- Two letter code: BR, DE, UK, US...
158
+ ```
159
+ bundle install
160
+ bundle exec rspec # needs a local mongod
40
161
 
41
- ## ISO 3366-2
162
+ ```
42
163
 
43
- Region/Province state code:
44
- BR-SP, BR-RJ, BR-MG, US-NY, US-WA, US-CA
164
+ Specs take a world tour (`spec/models/world_spec.rb`): Japan, Russia, Greece,
165
+ Egypt, India, Korea, Germany, the US, Singapore… add your country if it's
166
+ missing, that's the best PR you can send.
45
167
 
46
- ## Geometries
168
+ ## License
47
169
 
48
- Areas and points.
49
-
50
-
51
- ## Phone codes
52
-
53
- With the help of phonie, it's now easy to two way
54
- map entities and phone codes.
55
-
56
- ## Postal codes
57
-
58
- Great for address validation and form pre-population.
59
-
60
-
61
- Outside Rails
62
- -------------
63
-
64
- require 'geopolitical/models'
65
-
66
-
67
- Naming
68
- ------
69
-
70
- * Nation -> Country
71
- * Region -> State/Province
72
- * City -> District/Microregion
73
- * Hood -> Zone/Neighbourhood
74
-
75
-
76
- Each must be inside the former.
77
-
78
-
79
- Populate
80
- --------
81
-
82
- Use Geonames_local to populate data easily!
83
- "geonames_local"(https://github.com/fireho/geonames_local)
84
-
85
- Links
86
- -----
87
-
88
- http://download.geonames.org/export/dump/
89
- http://www.statoids.com/ubr.html
90
-
91
- This project rocks and uses MIT-LICENSE.
170
+ MIT. Bug reports and PRs at [fireho/geopolitical](https://github.com/fireho/geopolitical).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geopolitical
4
+ class ApplicationController < Geopolitical.parent_controller.constantize
5
+ protect_from_forgery with: :exception
6
+ layout 'geopolitical'
7
+ end
8
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geopolitical
4
+ class CitiesController < ApplicationController
5
+ before_action :set_city, only: %i[show edit update destroy]
6
+ before_action :set_form_options, only: %i[new edit create update]
7
+
8
+ def index
9
+ @cities = City.ordered
10
+ end
11
+
12
+ def show; end
13
+
14
+ def new
15
+ @city = City.new
16
+ end
17
+
18
+ def edit; end
19
+
20
+ def create
21
+ @city = City.new(city_params)
22
+ if @city.save
23
+ redirect_to city_path(@city), notice: t('geopolitical.flash.created', model: City.model_name.human)
24
+ else
25
+ render :new, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @city.update(city_params)
31
+ redirect_to city_path(@city), notice: t('geopolitical.flash.updated', model: City.model_name.human)
32
+ else
33
+ render :edit, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @city.destroy
39
+ redirect_to cities_path, notice: t('geopolitical.flash.destroyed', model: City.model_name.human)
40
+ end
41
+
42
+ private
43
+
44
+ def set_city
45
+ @city = City.find(params[:id])
46
+ end
47
+
48
+ def set_form_options
49
+ @nations = Nation.ordered.map { |nation| [nation.to_s, nation.id] }
50
+ @regions = Region.ordered.map { |region| [region.to_s, region.id] }
51
+ end
52
+
53
+ def city_params
54
+ params.require(:city).permit(:name, :slug, :nation_id, :region_id, :souls, :postal, :phone)
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geopolitical
4
+ class GeopoliticalController < ApplicationController
5
+ def index; end
6
+
7
+ def show
8
+ render :index
9
+ end
10
+
11
+ def new
12
+ redirect_to root_path
13
+ end
14
+
15
+ def edit
16
+ redirect_to root_path
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geopolitical
4
+ class HoodsController < ApplicationController
5
+ before_action :set_hood, only: %i[show edit update destroy]
6
+ before_action :set_city_options, only: %i[new edit create update]
7
+
8
+ def index
9
+ @hoods = Hood.ordered
10
+ end
11
+
12
+ def show; end
13
+
14
+ def new
15
+ @hood = Hood.new
16
+ end
17
+
18
+ def edit; end
19
+
20
+ def create
21
+ @hood = Hood.new(hood_params)
22
+ if @hood.save
23
+ redirect_to hood_path(@hood), notice: t('geopolitical.flash.created', model: Hood.model_name.human)
24
+ else
25
+ render :new, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @hood.update(hood_params)
31
+ redirect_to hood_path(@hood), notice: t('geopolitical.flash.updated', model: Hood.model_name.human)
32
+ else
33
+ render :edit, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @hood.destroy
39
+ redirect_to hoods_path, notice: t('geopolitical.flash.destroyed', model: Hood.model_name.human)
40
+ end
41
+
42
+ private
43
+
44
+ def set_hood
45
+ @hood = Hood.find(params[:id])
46
+ end
47
+
48
+ def set_city_options
49
+ @cities = City.ordered.map { |city| [city.to_s, city.id] }
50
+ end
51
+
52
+ def hood_params
53
+ params.require(:hood).permit(:name, :slug, :city_id, :souls, :rank, :postal, :phone)
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geopolitical
4
+ class NationsController < ApplicationController
5
+ before_action :set_nation, only: %i[show edit update destroy]
6
+
7
+ def index
8
+ @nations = Nation.ordered
9
+ end
10
+
11
+ def show; end
12
+
13
+ def new
14
+ @nation = Nation.new
15
+ end
16
+
17
+ def edit; end
18
+
19
+ def create
20
+ @nation = Nation.new(nation_params)
21
+ if @nation.save
22
+ redirect_to nation_path(@nation), notice: t('geopolitical.flash.created', model: Nation.model_name.human)
23
+ else
24
+ render :new, status: :unprocessable_entity
25
+ end
26
+ end
27
+
28
+ def update
29
+ if @nation.update(nation_params)
30
+ redirect_to nation_path(@nation), notice: t('geopolitical.flash.updated', model: Nation.model_name.human)
31
+ else
32
+ render :edit, status: :unprocessable_entity
33
+ end
34
+ end
35
+
36
+ def destroy
37
+ @nation.destroy
38
+ redirect_to nations_path, notice: t('geopolitical.flash.destroyed', model: Nation.model_name.human)
39
+ end
40
+
41
+ private
42
+
43
+ def set_nation
44
+ @nation = Nation.find(params[:id])
45
+ end
46
+
47
+ def nation_params
48
+ params.require(:nation).permit(:name, :abbr, :slug, :lang, :cash, :code, :code3, :tld, :postal, :phone)
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Geopolitical
4
+ class RegionsController < ApplicationController
5
+ before_action :set_region, only: %i[show edit update destroy]
6
+ before_action :set_nation_options, only: %i[new edit create update]
7
+
8
+ def index
9
+ @regions = Region.ordered
10
+ end
11
+
12
+ def show; end
13
+
14
+ def new
15
+ @region = Region.new
16
+ end
17
+
18
+ def edit; end
19
+
20
+ def create
21
+ @region = Region.new(region_params)
22
+ if @region.save
23
+ redirect_to region_path(@region), notice: t('geopolitical.flash.created', model: Region.model_name.human)
24
+ else
25
+ render :new, status: :unprocessable_entity
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @region.update(region_params)
31
+ redirect_to region_path(@region), notice: t('geopolitical.flash.updated', model: Region.model_name.human)
32
+ else
33
+ render :edit, status: :unprocessable_entity
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @region.destroy
39
+ redirect_to regions_path, notice: t('geopolitical.flash.destroyed', model: Region.model_name.human)
40
+ end
41
+
42
+ private
43
+
44
+ def set_region
45
+ @region = Region.find(params[:id])
46
+ end
47
+
48
+ def set_nation_options
49
+ @nations = Nation.ordered.map { |nation| [nation.to_s, nation.id] }
50
+ end
51
+
52
+ def region_params
53
+ params.require(:region).permit(:name, :abbr, :slug, :nation_id, :timezone, :postal, :phone)
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Geopolitical
2
4
  # Geopolitical Views Helper
3
5
  module ApplicationHelper