countries 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/countries/data.rb +12 -3
- data/lib/countries/subdivision.rb +1 -0
- data/lib/countries/version.rb +1 -1
- data/spec/data_spec.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 735b197a9e7e8fda800a39ab7e2558da8ee59b80
|
4
|
+
data.tar.gz: 7af8cbb88f8301bf72f8831fffffa2d556f38a81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d3b4230c7a1500f5eab70351d027b1ede91811817cac14e8e602a222d7fdc68b61bb8af5ef5b8150e5ae888e9e9ce01cc003dd85e6b27c33c8e822e9ddcf127
|
7
|
+
data.tar.gz: 8e9d46e88acad56b12dbead0157f0895a4c80b10bc850e3bf26fe15a10a950241d5ee54763719d39cf332a236eb16e62c99d5488bfad7a6e891997bad2af19b3
|
data/lib/countries/data.rb
CHANGED
@@ -2,6 +2,7 @@ module ISO3166
|
|
2
2
|
##
|
3
3
|
# Handles building the in memory store of countries data
|
4
4
|
class Data
|
5
|
+
@@cache_dir = [File.dirname(__FILE__), 'cache']
|
5
6
|
@@cache = {}
|
6
7
|
@@registered_data = {}
|
7
8
|
|
@@ -14,6 +15,14 @@ module ISO3166
|
|
14
15
|
end
|
15
16
|
|
16
17
|
class << self
|
18
|
+
def cache_dir
|
19
|
+
@@cache_dir
|
20
|
+
end
|
21
|
+
|
22
|
+
def cache_dir=(value)
|
23
|
+
@@cache_dir = value
|
24
|
+
end
|
25
|
+
|
17
26
|
def register(data)
|
18
27
|
alpha2 = data[:alpha2].upcase
|
19
28
|
@@registered_data[alpha2] = \
|
@@ -52,7 +61,7 @@ module ISO3166
|
|
52
61
|
|
53
62
|
def load_data!
|
54
63
|
return @@cache unless load_required?
|
55
|
-
@@cache = load_cache %w(
|
64
|
+
@@cache = load_cache %w(countries.json)
|
56
65
|
@@_country_codes = @@cache.keys
|
57
66
|
@@cache = @@cache.merge(@@registered_data)
|
58
67
|
@@cache
|
@@ -106,7 +115,7 @@ module ISO3166
|
|
106
115
|
end
|
107
116
|
|
108
117
|
def load_translations(locale)
|
109
|
-
locale_names = load_cache(['
|
118
|
+
locale_names = load_cache(['locales', "#{locale}.json"])
|
110
119
|
internal_codes.each do |alpha2|
|
111
120
|
@@cache[alpha2]['translations'] ||= Translations.new
|
112
121
|
@@cache[alpha2]['translations'][locale] = locale_names[alpha2].freeze
|
@@ -129,7 +138,7 @@ module ISO3166
|
|
129
138
|
end
|
130
139
|
|
131
140
|
def datafile_path(file_array)
|
132
|
-
File.join([
|
141
|
+
File.join([@@cache_dir] + file_array)
|
133
142
|
end
|
134
143
|
end
|
135
144
|
end
|
data/lib/countries/version.rb
CHANGED
data/spec/data_spec.rb
CHANGED
@@ -81,12 +81,12 @@ describe ISO3166::Data do
|
|
81
81
|
|
82
82
|
describe '#load_cache' do
|
83
83
|
it 'will return an empty hash for an unsupported locale' do
|
84
|
-
file_array = %w(
|
84
|
+
file_array = %w(locales unsupported.json)
|
85
85
|
expect(ISO3166::Data.send(:load_cache, file_array)).to eql({})
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'will return json for a supported locale' do
|
89
|
-
file_array = %w(
|
89
|
+
file_array = %w(locales en.json)
|
90
90
|
expect(ISO3166::Data.send(:load_cache, file_array)).not_to be_empty
|
91
91
|
end
|
92
92
|
end
|