torasup 0.0.15 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/torasup.rb +6 -3
- data/lib/torasup/configuration.rb +7 -2
- data/lib/torasup/version.rb +1 -1
- data/spec/support/custom_pstn_2.yaml +6 -0
- data/spec/support/pstn_helpers.rb +8 -3
- data/spec/torasup/configuration_spec.rb +29 -7
- data/spec/torasup/operator_spec.rb +19 -3
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5383412630638aec5f64180496cc1e120e16896f
|
4
|
+
data.tar.gz: a3e569658c46e1d0d080de3473f67bc83e679f07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 274e51bffadf55b2f54dd8b7685f2d723dfa1adfb95bfd3f531549ee93e452fb8eb2e5bf3798ca6409cc34a9305572927fb63d27a94d8f71061509c287519df5
|
7
|
+
data.tar.gz: e8bb07f93569f4094923ed9c89d44506cd94813ae22225c37f161afe6bc88fe5e6f0dd1973cd82d6dff7161a47e98be81c5f3a291c4adfad9b7b9277058ed837
|
data/lib/torasup.rb
CHANGED
@@ -28,9 +28,12 @@ module Torasup
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def load_pstn_data!
|
31
|
-
@pstn_data = load_yaml_file(File.join(File.dirname(__FILE__), 'torasup/data/pstn.yaml'))
|
32
|
-
|
33
|
-
|
31
|
+
@pstn_data = load_yaml_file(File.join(File.dirname(__FILE__), 'torasup/data/pstn.yaml'))
|
32
|
+
configuration.custom_pstn_data_files.compact.each do |pstn_data_file|
|
33
|
+
@pstn_data.deeper_merge!(
|
34
|
+
load_yaml_file(pstn_data_file)
|
35
|
+
)
|
36
|
+
end
|
34
37
|
load_pstn_prefixes!
|
35
38
|
end
|
36
39
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Configuration
|
2
2
|
DEFAULT_COUNTRIES = ["US", "GB", "AU", "IT", "RU", "NO"]
|
3
|
-
attr_accessor :registered_operators, :default_countries, :
|
3
|
+
attr_accessor :registered_operators, :default_countries, :custom_pstn_data_files
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@default_countries = DEFAULT_COUNTRIES
|
@@ -12,7 +12,8 @@ class Configuration
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def custom_pstn_data_file=(value)
|
15
|
-
@
|
15
|
+
@custom_pstn_data_files ||= []
|
16
|
+
value ? (@custom_pstn_data_files << value) : @custom_pstn_data_files.clear
|
16
17
|
Torasup.load_pstn_data!
|
17
18
|
end
|
18
19
|
|
@@ -29,4 +30,8 @@ class Configuration
|
|
29
30
|
def registered_operators
|
30
31
|
@registered_operators ||= {}
|
31
32
|
end
|
33
|
+
|
34
|
+
def custom_pstn_data_files
|
35
|
+
(@custom_pstn_data_files ||= []).compact
|
36
|
+
end
|
32
37
|
end
|
data/lib/torasup/version.rb
CHANGED
@@ -25,9 +25,14 @@ module PstnHelpers
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def configure_with_custom_data
|
29
|
-
|
30
|
-
|
28
|
+
def configure_with_custom_data(options = {})
|
29
|
+
custom_data_files = ["custom_pstn.yaml"]
|
30
|
+
custom_data_files << "custom_pstn_2.yaml" if options[:multiple_files]
|
31
|
+
|
32
|
+
custom_data_files.each do |custom_data_file|
|
33
|
+
Torasup.configure do |config|
|
34
|
+
config.custom_pstn_data_file = File.join(File.dirname(__FILE__), "../support", "/#{custom_data_file}")
|
35
|
+
end
|
31
36
|
end
|
32
37
|
end
|
33
38
|
end
|
@@ -61,16 +61,38 @@ describe Torasup do
|
|
61
61
|
end
|
62
62
|
|
63
63
|
describe "#custom_pstn_data_file=('path_to_yaml_file.yaml')" do
|
64
|
-
|
64
|
+
def setup_expectations
|
65
65
|
allow(Torasup).to receive(:load_pstn_data!)
|
66
|
+
expect(Torasup).to receive(:load_pstn_data!)
|
66
67
|
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
def setup_scenario
|
70
|
+
setup_expectations
|
71
|
+
end
|
72
|
+
|
73
|
+
before do
|
74
|
+
setup_scenario
|
75
|
+
end
|
76
|
+
|
77
|
+
context "setting a custom pstn data file" do
|
78
|
+
it "should set a custom pstn data file and reload the data" do
|
79
|
+
Torasup.configure do |config|
|
80
|
+
expect(config.custom_pstn_data_files).to eq([])
|
81
|
+
config.custom_pstn_data_file = "foo.yaml"
|
82
|
+
expect(config.custom_pstn_data_files).to eq(["foo.yaml"])
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "setting the custom pstn data file to nil" do
|
88
|
+
it "should clear the pstn data files and reload the data" do
|
89
|
+
Torasup.configure do |config|
|
90
|
+
expect(config.custom_pstn_data_files).to eq([])
|
91
|
+
config.custom_pstn_data_file = "foo.yaml"
|
92
|
+
expect(config.custom_pstn_data_files).to eq(["foo.yaml"])
|
93
|
+
config.custom_pstn_data_file = nil
|
94
|
+
expect(config.custom_pstn_data_files).to eq([])
|
95
|
+
end
|
74
96
|
end
|
75
97
|
end
|
76
98
|
end
|
@@ -82,11 +82,27 @@ module Torasup
|
|
82
82
|
|
83
83
|
context "using overridden data" do
|
84
84
|
before do
|
85
|
-
configure_with_custom_data
|
85
|
+
configure_with_custom_data(configuration_options)
|
86
86
|
end
|
87
87
|
|
88
|
-
|
89
|
-
let(:
|
88
|
+
context "with a single configuration file" do
|
89
|
+
let(:configuration_options) { {} }
|
90
|
+
|
91
|
+
it_should_behave_like "an operator" do
|
92
|
+
let(:options) { { :with_custom_pstn_data => true } }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with multiple configuration files" do
|
97
|
+
let(:configuration_options) { {:multiple_files => true} }
|
98
|
+
|
99
|
+
def assert_overridden_data!
|
100
|
+
torasup_number = Torasup::PhoneNumber.new("85515234567")
|
101
|
+
operator = torasup_number.operator
|
102
|
+
expect(operator.my_custom_property_2).to eq("hello-foo-2")
|
103
|
+
end
|
104
|
+
|
105
|
+
it { assert_overridden_data! }
|
90
106
|
end
|
91
107
|
end
|
92
108
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: torasup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Wilkie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: countries
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- lib/torasup/version.rb
|
106
106
|
- spec/spec_helper.rb
|
107
107
|
- spec/support/custom_pstn.yaml
|
108
|
+
- spec/support/custom_pstn_2.yaml
|
108
109
|
- spec/support/custom_pstn_spec.yaml
|
109
110
|
- spec/support/pstn_helpers.rb
|
110
111
|
- spec/support/pstn_spec.yaml
|
@@ -134,13 +135,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.5.2
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: '"Retuns metadata about a phone number such as operator, area code and more"'
|
141
142
|
test_files:
|
142
143
|
- spec/spec_helper.rb
|
143
144
|
- spec/support/custom_pstn.yaml
|
145
|
+
- spec/support/custom_pstn_2.yaml
|
144
146
|
- spec/support/custom_pstn_spec.yaml
|
145
147
|
- spec/support/pstn_helpers.rb
|
146
148
|
- spec/support/pstn_spec.yaml
|