cloudflare_localizable 0.1.1 → 0.1.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 +5 -5
- data/.rspec +2 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -1
- data/.travis.yml +5 -4
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/console +2 -0
- data/cloudflare_localizable.gemspec +4 -2
- data/lib/cloudflare_localizable.rb +6 -5
- data/lib/cloudflare_localizable/country.rb +12 -3
- data/lib/cloudflare_localizable/country_list.rb +3 -2
- data/lib/cloudflare_localizable/version.rb +3 -1
- metadata +27 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9d6007461042c4f48b203ba0329c5425f9a77bf5047ad18664dea26f58d924ce
|
4
|
+
data.tar.gz: df71329ae0f016a4402896f82234bd45e8e4885fd7cb4451e05cfd31e57270ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca1987748c2dc9ba972fa599ae28e8497647cd600011b90d09d77f699dfae7dba472b6d1bd8a082c7f62b173e06bdfa233eb8c0cb697b6714d8ee9cd851d5331
|
7
|
+
data.tar.gz: 8c9130523bede2ad4a1694b6adb002ab11a71644992b5f10c90d4eebd931043f4764fabc4f8e1bb248ce2097f4c4e11651bdfadba40bc0c2a7848cc6ed10b175
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.0
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
|
@@ -21,8 +22,9 @@ Gem::Specification.new do |spec|
|
|
21
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
23
|
spec.require_paths = ['lib']
|
23
24
|
|
25
|
+
spec.add_development_dependency 'actionpack', '~> 4.2', '>= 4.2.5'
|
24
26
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
25
27
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
28
|
spec.add_development_dependency 'rspec', '~> 3.4', '>= 3.4.0'
|
27
|
-
spec.add_development_dependency '
|
29
|
+
spec.add_development_dependency 'rubocop', '~> 0.54.0'
|
28
30
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflare_localizable/version'
|
2
4
|
require 'cloudflare_localizable/country'
|
3
5
|
|
4
|
-
# This module can be included in any Rails controller that needs country
|
5
|
-
#
|
6
|
-
# need to know the country of the user.
|
6
|
+
# This module can be included in any Rails controller that needs country information. You get a
|
7
|
+
# helper method called cf_country to be used whenever you need to know the country of the user.
|
7
8
|
#
|
8
9
|
# === Example
|
9
10
|
#
|
@@ -16,7 +17,7 @@ require 'cloudflare_localizable/country'
|
|
16
17
|
# end
|
17
18
|
# end
|
18
19
|
module CloudFlareLocalizable
|
19
|
-
CF_HEADER = 'HTTP_CF_IPCOUNTRY'
|
20
|
+
CF_HEADER = 'HTTP_CF_IPCOUNTRY'
|
20
21
|
|
21
22
|
def self.included(base)
|
22
23
|
base.send(:helper_method, :cf_country)
|
@@ -24,6 +25,6 @@ module CloudFlareLocalizable
|
|
24
25
|
|
25
26
|
# Returns the real name of the country, based on the country code.
|
26
27
|
def cf_country
|
27
|
-
@
|
28
|
+
@cf_country ||= Country.find(request.headers[CF_HEADER] || 'XX')
|
28
29
|
end
|
29
30
|
end
|
@@ -1,16 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'cloudflare_localizable/country_list'
|
2
4
|
|
3
5
|
module CloudFlareLocalizable
|
6
|
+
# This class represents a country, and stores name and code for the countries.
|
7
|
+
#
|
8
|
+
# === Example
|
9
|
+
#
|
10
|
+
# country = Country.find('BB')
|
11
|
+
# country.code # => "BB"
|
12
|
+
# country.name # => "Barbados"
|
4
13
|
class Country
|
5
14
|
attr_accessor :name, :code
|
6
15
|
|
7
16
|
def self.find(code)
|
8
|
-
record = CF_COUNTRIES.find { |country| country[:code] == code }
|
17
|
+
record = CF_COUNTRIES.find { |country| country[:code] == code } || {}
|
9
18
|
|
10
|
-
new(record
|
19
|
+
new(record.fetch(:code, 'XX'), record.fetch(:name, 'Unknown'))
|
11
20
|
end
|
12
21
|
|
13
|
-
def initialize(code, name)
|
22
|
+
def initialize(code = 'XX', name = 'Unknown')
|
14
23
|
self.code = code
|
15
24
|
self.name = name
|
16
25
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module CloudFlareLocalizable
|
3
4
|
# Countries
|
4
5
|
CF_COUNTRIES = [
|
@@ -252,5 +253,5 @@ module CloudFlareLocalizable
|
|
252
253
|
{ code: 'ZM', name: 'Zambia' },
|
253
254
|
{ code: 'ZW', name: 'Zimbabwe' },
|
254
255
|
{ code: 'XX', name: 'Unknown' }
|
255
|
-
]
|
256
|
+
].freeze
|
256
257
|
end
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare_localizable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 4.2.5
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '4.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 4.2.5
|
13
33
|
- !ruby/object:Gem::Dependency
|
14
34
|
name: bundler
|
15
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,25 +79,19 @@ dependencies:
|
|
59
79
|
- !ruby/object:Gem::Version
|
60
80
|
version: 3.4.0
|
61
81
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
82
|
+
name: rubocop
|
63
83
|
requirement: !ruby/object:Gem::Requirement
|
64
84
|
requirements:
|
65
85
|
- - "~>"
|
66
86
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
68
|
-
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: 4.2.5
|
87
|
+
version: 0.54.0
|
71
88
|
type: :development
|
72
89
|
prerelease: false
|
73
90
|
version_requirements: !ruby/object:Gem::Requirement
|
74
91
|
requirements:
|
75
92
|
- - "~>"
|
76
93
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
-
- - ">="
|
79
|
-
- !ruby/object:Gem::Version
|
80
|
-
version: 4.2.5
|
94
|
+
version: 0.54.0
|
81
95
|
description: |-
|
82
96
|
If you're using CloudFlare you can easily get the location of your requests
|
83
97
|
based on a special header that CloudFlare attaches to every request.
|
@@ -89,6 +103,7 @@ extra_rdoc_files: []
|
|
89
103
|
files:
|
90
104
|
- ".gitignore"
|
91
105
|
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
92
107
|
- ".ruby-version"
|
93
108
|
- ".travis.yml"
|
94
109
|
- Gemfile
|
@@ -122,9 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
137
|
version: '0'
|
123
138
|
requirements: []
|
124
139
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
140
|
+
rubygems_version: 2.7.3
|
126
141
|
signing_key:
|
127
142
|
specification_version: 4
|
128
143
|
summary: Localize your requests with CloudFlare.
|
129
144
|
test_files: []
|
130
|
-
has_rdoc:
|