countries 5.1.0 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.markdown +3 -0
- data/lib/countries/country/class_methods.rb +0 -20
- data/lib/countries/country.rb +2 -2
- data/lib/countries/data/countries/VI.yaml +1 -0
- data/lib/countries/data.rb +26 -0
- data/lib/countries/version.rb +1 -1
- data/spec/data_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ba15249a08854651cd8bba33f527c450145bce3c156c1dca3d0d1a60107d8f2
|
4
|
+
data.tar.gz: f4c0d30dd51686895801e21c7ff99b665b981f0fce46f9541f105091bbd942d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8af15c8ee5f6ef03c8a65eb3529c6ed4facab419ed8e8336ee3af58b474cab0bc3291cd7785e4105a05a741160104fce419f678f769dd075a4c6cfdc45fdf2e
|
7
|
+
data.tar.gz: 892d45e8c1f4d1c2ac95d4fde2d8294f9ea367a1123f5648bdc107056124d44b57d174bfba6d3caff66502db0b5f12dc8b13873611e4ac9611a9f25f1065a8fe
|
data/CHANGELOG.md
CHANGED
@@ -3,9 +3,22 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project adheres to [Semantic Versioning](https://semver.org/).
|
5
5
|
|
6
|
+
## [5.1.1](https://github.com/countries/countries/releases/tag/v5.1.1') (2022/07/18 09:10 +00:00)
|
7
|
+
|
8
|
+
**Important changes**
|
9
|
+
|
10
|
+
- Subdivision loading now respects the configured locales and will only load subdivision translations for the configured locales instead of loading all translations. This fixes [\#580](https://github.com/countries/countries/issues/580)
|
11
|
+
|
12
|
+
**Merged pull requests:**
|
13
|
+
|
14
|
+
* Refactor subdivision loading to respect the configured locales. [\#762](https://github.com/countries/countries/pull/762) ([pmor](https://github.com/pmor))
|
15
|
+
* Add an alternative name for USVI lookup [\#763](https://github.com/countries/countries/pull/763) ([tadejm](https://github.com/tadejm))
|
16
|
+
|
17
|
+
|
6
18
|
## [5.1.0](https://github.com/countries/countries/releases/tag/v5.1.0') (2022/06/27 07:50 +00:00)
|
7
19
|
|
8
20
|
**Important changes**
|
21
|
+
|
9
22
|
- `Subdivision` now has a `type` attribute obtained from ISO3166-2 subdivision types. `type` is a _lowercase_ and _snake_cased_ string.
|
10
23
|
- Adds `Country#subdivision_types` and `#humanized_subdivision_types` to list a country's subdivision types
|
11
24
|
- Adds `Country#subdivisions_of_types(types)` to allow getting subdivisions of given type(s)
|
data/README.markdown
CHANGED
@@ -256,6 +256,9 @@ ISO3166.configure do |config|
|
|
256
256
|
end
|
257
257
|
```
|
258
258
|
|
259
|
+
If you change the value of `ISO3166.configuration.locales` after initialization, you should call `ISO3166::Data.reset` to reset the data cache, or you may end up with inconsistently loaded locales.
|
260
|
+
As of 5.1.1, subdivision translations also respect this and will only load the selected locales.
|
261
|
+
|
259
262
|
## Loading Custom Data
|
260
263
|
|
261
264
|
As of 2.0 countries supports loading custom countries / overriding data in its data set, though if you choose to do this please contribute back to the upstream repo!
|
@@ -64,17 +64,6 @@ module ISO3166
|
|
64
64
|
translations.merge(custom_countries)
|
65
65
|
end
|
66
66
|
|
67
|
-
def subdivisions(alpha2)
|
68
|
-
@subdivisions ||= {}
|
69
|
-
@subdivisions[alpha2] ||= create_subdivisions(subdivision_data(alpha2))
|
70
|
-
end
|
71
|
-
|
72
|
-
def create_subdivisions(subdivision_data)
|
73
|
-
subdivision_data.each_with_object({}) do |(k, v), hash|
|
74
|
-
hash[k] = Subdivision.new(v)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
67
|
protected
|
79
68
|
|
80
69
|
def strip_accents(string)
|
@@ -85,15 +74,6 @@ module ISO3166
|
|
85
74
|
end
|
86
75
|
end
|
87
76
|
|
88
|
-
def subdivision_data(alpha2)
|
89
|
-
file = subdivision_file_path(alpha2)
|
90
|
-
File.exist?(file) ? YAML.load_file(file) : {}
|
91
|
-
end
|
92
|
-
|
93
|
-
def subdivision_file_path(alpha2)
|
94
|
-
File.join(File.dirname(__FILE__), '..', 'data', 'subdivisions', "#{alpha2}.yaml")
|
95
|
-
end
|
96
|
-
|
97
77
|
# Some methods like parse_value are expensive in that they
|
98
78
|
# create a large number of objects internally. In order to reduce the
|
99
79
|
# object creations and save the GC, we can cache them in an class instance
|
data/lib/countries/country.rb
CHANGED
@@ -58,9 +58,9 @@ module ISO3166
|
|
58
58
|
# @return [Array<ISO3166::Subdivision>] the list of subdivisions for this Country.
|
59
59
|
def subdivisions
|
60
60
|
@subdivisions ||= if data['subdivisions']
|
61
|
-
|
61
|
+
ISO3166::Data.create_subdivisions(data['subdivisions'])
|
62
62
|
else
|
63
|
-
|
63
|
+
ISO3166::Data.subdivisions(alpha2)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
data/lib/countries/data.rb
CHANGED
@@ -8,6 +8,7 @@ module ISO3166
|
|
8
8
|
@loaded_country_codes = []
|
9
9
|
@registered_data = {}
|
10
10
|
@mutex = Mutex.new
|
11
|
+
@subdivisions = {}
|
11
12
|
|
12
13
|
def initialize(alpha2)
|
13
14
|
@alpha2 = alpha2.to_s.upcase
|
@@ -44,6 +45,7 @@ module ISO3166
|
|
44
45
|
# Resets the loaded data and cache
|
45
46
|
def reset
|
46
47
|
@cache = {}
|
48
|
+
@subdivisions = {}
|
47
49
|
@registered_data = {}
|
48
50
|
ISO3166.configuration.loaded_locales = []
|
49
51
|
end
|
@@ -68,6 +70,26 @@ module ISO3166
|
|
68
70
|
File.join([@cache_dir] + file_array)
|
69
71
|
end
|
70
72
|
|
73
|
+
def subdivision_data(alpha2)
|
74
|
+
file = subdivision_file_path(alpha2)
|
75
|
+
data = File.exist?(file) ? YAML.load_file(file) : {}
|
76
|
+
locales = ISO3166.configuration.locales.map(&:to_s)
|
77
|
+
data.each_value{ |v| v['translations'] = v['translations'].slice(*locales)}
|
78
|
+
|
79
|
+
return data
|
80
|
+
end
|
81
|
+
|
82
|
+
def subdivisions(alpha2)
|
83
|
+
@subdivisions ||= {}
|
84
|
+
@subdivisions[alpha2] ||= create_subdivisions(ISO3166::Data.subdivision_data(alpha2))
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_subdivisions(subdivision_data)
|
88
|
+
subdivision_data.each_with_object({}) do |(k, v), hash|
|
89
|
+
hash[k] = Subdivision.new(v)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
71
93
|
private
|
72
94
|
|
73
95
|
def load_data!
|
@@ -176,6 +198,10 @@ module ISO3166
|
|
176
198
|
|
177
199
|
data
|
178
200
|
end
|
201
|
+
|
202
|
+
def subdivision_file_path(alpha2)
|
203
|
+
File.join(File.dirname(__FILE__), 'data', 'subdivisions', "#{alpha2}.yaml")
|
204
|
+
end
|
179
205
|
end
|
180
206
|
end
|
181
207
|
end
|
data/lib/countries/version.rb
CHANGED
data/spec/data_spec.rb
CHANGED
@@ -26,6 +26,17 @@ describe ISO3166::Data do
|
|
26
26
|
expect(data['translated_names'].size).to eq 1
|
27
27
|
end
|
28
28
|
|
29
|
+
it 'only loads subdivision translations for the configured locales' do
|
30
|
+
ISO3166.configuration.locales = %i[en]
|
31
|
+
ISO3166::Data.reset
|
32
|
+
subdivisions = ISO3166::Data.subdivisions('US')
|
33
|
+
expect(subdivisions.values.first['translations'].keys).to eq(%w[en])
|
34
|
+
ISO3166.configuration.locales = %i[es de en]
|
35
|
+
ISO3166::Data.reset
|
36
|
+
subdivisions = ISO3166::Data.subdivisions('US')
|
37
|
+
expect(subdivisions.values.first['translations'].keys).to eq(%w[es de en])
|
38
|
+
end
|
39
|
+
|
29
40
|
describe '#codes' do
|
30
41
|
it 'returns an array' do
|
31
42
|
data = ISO3166::Data.codes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Robinson
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2022-
|
14
|
+
date: 2022-07-18 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: sixarm_ruby_unaccent
|