phony_rails 0.5.0 → 0.6.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.
- data/Gemfile.lock +3 -3
- data/README.md +6 -3
- data/lib/phony_rails/version.rb +1 -1
- data/lib/phony_rails.rb +2 -2
- data/lib/validators/phony_validator.rb +21 -1
- data/phony_rails.gemspec +1 -1
- data/spec/lib/phony_rails_spec.rb +16 -16
- data/spec/lib/validators/phony_validator_spec.rb +5 -5
- metadata +21 -9
- checksums.yaml +0 -15
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
phony_rails (0.
|
4
|
+
phony_rails (0.6.0)
|
5
5
|
activesupport (>= 3.0)
|
6
6
|
countries (>= 0.8.2)
|
7
|
-
phony (
|
7
|
+
phony (~> 2.1)
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
@@ -49,7 +49,7 @@ GEM
|
|
49
49
|
moped (1.5.1)
|
50
50
|
multi_json (1.7.9)
|
51
51
|
origin (1.1.0)
|
52
|
-
phony (2.
|
52
|
+
phony (2.1.3)
|
53
53
|
rake (10.1.0)
|
54
54
|
rb-fsevent (0.9.3)
|
55
55
|
rb-inotify (0.9.1)
|
data/README.md
CHANGED
@@ -26,7 +26,6 @@ Or install it yourself as:
|
|
26
26
|
For **ActiveRecord**, in your model add:
|
27
27
|
|
28
28
|
class SomeModel < ActiveRecord::Base
|
29
|
-
|
30
29
|
# Normalizes the attribute itself before validation
|
31
30
|
phony_normalize :phone_number, :default_country_code => 'US'
|
32
31
|
|
@@ -108,7 +107,7 @@ You can also use the bang method (phony_formatted!):
|
|
108
107
|
|
109
108
|
number = "010-12341234"
|
110
109
|
number.phony_formatted!(:normalize => :NL, :format => :international)
|
111
|
-
number # => "+31 10
|
110
|
+
number # => "+31 10 123 41234"
|
112
111
|
|
113
112
|
### Find by normalized number
|
114
113
|
|
@@ -118,6 +117,9 @@ Say you want to find a record by a phone number. Best is to normalize user input
|
|
118
117
|
|
119
118
|
## Changelog
|
120
119
|
|
120
|
+
0.6.0
|
121
|
+
* Support for Phony 2.1 by @pjg.
|
122
|
+
|
121
123
|
0.5.0
|
122
124
|
* Added :strict option to String#phony_formatted.
|
123
125
|
|
@@ -177,6 +179,7 @@ Say you want to find a record by a phone number. Best is to normalize user input
|
|
177
179
|
|
178
180
|
## TODO
|
179
181
|
|
182
|
+
* Fix phony v2.x issues.
|
180
183
|
* Make this work: Home.find_by_normalized_phone_number(Home.normalize_number(params[:phone_number]))
|
181
184
|
So we use Home.normalize_number instead of PhonyRails.normalize_number. This way we can use the same default_country_code.
|
182
185
|
* Make country_code method configurable.
|
@@ -189,4 +192,4 @@ Say you want to find a record by a phone number. Best is to normalize user input
|
|
189
192
|
4. Push to the branch (`git push origin my-new-feature`)
|
190
193
|
5. Create new Pull Request
|
191
194
|
|
192
|
-
Don't forget to add tests and run rspec before creating a pull request :)
|
195
|
+
Don't forget to add tests and run rspec before creating a pull request :)
|
data/lib/phony_rails/version.rb
CHANGED
data/lib/phony_rails.rb
CHANGED
@@ -30,8 +30,8 @@ module PhonyRails
|
|
30
30
|
# Add default_country_number if missing
|
31
31
|
number = "#{default_country_number}#{number}" if not number =~ /^(00|\+|#{default_country_number})/
|
32
32
|
end
|
33
|
-
|
34
|
-
|
33
|
+
|
34
|
+
Phony.normalize(number)
|
35
35
|
rescue
|
36
36
|
number # If all goes wrong .. we still return the original input.
|
37
37
|
end
|
@@ -6,7 +6,27 @@ class PhonyPlausibleValidator < ActiveModel::EachValidator
|
|
6
6
|
# Validates a String using Phony.plausible? method.
|
7
7
|
def validate_each(record, attribute, value)
|
8
8
|
return if value.blank?
|
9
|
-
|
9
|
+
|
10
|
+
@record = record
|
11
|
+
@record.errors.add(attribute, error_message) if not Phony.plausible?(value, cc: country_code_or_country_number)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def error_message
|
17
|
+
options[:message] || :improbable_phone
|
18
|
+
end
|
19
|
+
|
20
|
+
def country_code_or_country_number
|
21
|
+
options[:country_code] || record_country_number || record_country_code
|
22
|
+
end
|
23
|
+
|
24
|
+
def record_country_number
|
25
|
+
@record.country_number if @record.respond_to?(:country_number)
|
26
|
+
end
|
27
|
+
|
28
|
+
def record_country_code
|
29
|
+
@record.country_code if @record.respond_to?(:country_code)
|
10
30
|
end
|
11
31
|
|
12
32
|
end
|
data/phony_rails.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.require_paths = ["lib"]
|
17
17
|
gem.version = PhonyRails::VERSION
|
18
18
|
|
19
|
-
gem.add_dependency "phony", "
|
19
|
+
gem.add_dependency "phony", "~> 2.1"
|
20
20
|
gem.add_dependency "countries", ">= 0.8.2"
|
21
21
|
gem.add_dependency "activesupport", ">= 3.0"
|
22
22
|
gem.add_development_dependency "activerecord", ">= 3.0"
|
@@ -11,8 +11,8 @@ describe PhonyRails do
|
|
11
11
|
|
12
12
|
it "should change the String using the bang method" do
|
13
13
|
s = "0101234123"
|
14
|
-
s.phony_formatted!(:normalize => :NL, :format => :international).should eql('+31 10
|
15
|
-
s.should eql("+31 10
|
14
|
+
s.phony_formatted!(:normalize => :NL, :format => :international).should eql('+31 10 123 4123')
|
15
|
+
s.should eql("+31 10 123 4123")
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
@@ -36,26 +36,26 @@ describe PhonyRails do
|
|
36
36
|
describe 'with normalize option' do
|
37
37
|
|
38
38
|
it "should phony_format" do
|
39
|
-
"
|
40
|
-
"
|
39
|
+
"101234123".phony_formatted(:normalize => :NL).should eql('010 123 4123')
|
40
|
+
"101234123".phony_formatted(:normalize => :NL, :format => :international).should eql('+31 10 123 4123')
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should not change original String" do
|
44
44
|
s = "0101234123"
|
45
|
-
s.phony_formatted(:normalize => :NL).should eql('010
|
45
|
+
s.phony_formatted(:normalize => :NL).should eql('010 123 4123')
|
46
46
|
s.should eql("0101234123")
|
47
47
|
end
|
48
48
|
|
49
49
|
it "should phony_format String with country code" do
|
50
|
-
"31101234123".phony_formatted(:normalize => :NL).should eql('010
|
50
|
+
"31101234123".phony_formatted(:normalize => :NL).should eql('010 123 4123')
|
51
51
|
end
|
52
52
|
|
53
53
|
it "should phony_format String with country code" do
|
54
|
-
"31101234123".phony_formatted(:normalize => :NL).should eql('010
|
54
|
+
"31101234123".phony_formatted(:normalize => :NL).should eql('010 123 4123')
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should accept strings with non-digits in it" do
|
58
|
-
"+31-10-1234123".phony_formatted(:normalize => :NL, :format => :international, :spaces => '-').should eql('+31-10-
|
58
|
+
"+31-10-1234123".phony_formatted(:normalize => :NL, :format => :international, :spaces => '-').should eql('+31-10-123-4123')
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should phony_format String with country code different than normalized value" do
|
@@ -75,16 +75,16 @@ describe PhonyRails do
|
|
75
75
|
|
76
76
|
it "should not change original String" do
|
77
77
|
s = "0101234123"
|
78
|
-
s.phony_formatted(:normalize => :NL).should eql('010
|
78
|
+
s.phony_formatted(:normalize => :NL).should eql('010 123 4123')
|
79
79
|
s.should eql("0101234123")
|
80
80
|
end
|
81
81
|
|
82
82
|
it "should phony_format a digits string with spaces String" do
|
83
|
-
"31 10 1234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-
|
83
|
+
"31 10 1234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-123-4123')
|
84
84
|
end
|
85
85
|
|
86
86
|
it "should phony_format a digits String" do
|
87
|
-
"31101234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-
|
87
|
+
"31101234123".phony_formatted(:format => :international, :spaces => '-').should eql('+31-10-123-4123')
|
88
88
|
end
|
89
89
|
|
90
90
|
it "returns nil if implausible phone" do
|
@@ -148,11 +148,11 @@ describe PhonyRails do
|
|
148
148
|
PhonyRails.normalize_number('070-4157134', :country_code => 'NL').should eql('31704157134')
|
149
149
|
PhonyRails.normalize_number('0031-70-4157134', :country_code => 'NL').should eql('31704157134')
|
150
150
|
PhonyRails.normalize_number('+31-70-4157134', :country_code => 'NL').should eql('31704157134')
|
151
|
-
PhonyRails.normalize_number('0323-2269497', :country_code => 'BE').should eql('
|
151
|
+
PhonyRails.normalize_number('0323-2269497', :country_code => 'BE').should eql('3232269497')
|
152
152
|
end
|
153
153
|
|
154
|
-
it "should
|
155
|
-
PhonyRails.normalize_number('01').should eql('
|
154
|
+
it "should normalize even an implausible number" do
|
155
|
+
PhonyRails.normalize_number('01').should eql('1')
|
156
156
|
end
|
157
157
|
end
|
158
158
|
|
@@ -225,9 +225,9 @@ describe PhonyRails do
|
|
225
225
|
end
|
226
226
|
|
227
227
|
# Following examples have incomplete number
|
228
|
-
it "should
|
228
|
+
it "should normalize even a unplausible number (no country code)" do
|
229
229
|
model = model_klass.new(:phone_attribute => "(0)10-1234123")
|
230
|
-
model.normalized_phone_attribute.should eql('
|
230
|
+
model.normalized_phone_attribute.should eql('101234123')
|
231
231
|
end
|
232
232
|
|
233
233
|
it "should use country_code option" do
|
@@ -93,11 +93,11 @@ end
|
|
93
93
|
#-----------------------------------------------------------------------------------------------------------------------
|
94
94
|
|
95
95
|
I18n.locale = :en
|
96
|
-
VALID_NUMBER = '
|
96
|
+
VALID_NUMBER = '1 555 555 5555'
|
97
97
|
AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '61390133997'
|
98
98
|
FORMATTED_AUSTRALIAN_NUMBER_WITH_COUNTRY_CODE = '+61 390133997'
|
99
|
-
FRENCH_NUMBER_WITH_COUNTRY_CODE = '
|
100
|
-
FORMATTED_FRENCH_NUMBER_WITH_COUNTRY_CODE = '+33
|
99
|
+
FRENCH_NUMBER_WITH_COUNTRY_CODE = '33627899541'
|
100
|
+
FORMATTED_FRENCH_NUMBER_WITH_COUNTRY_CODE = '+33 627899541'
|
101
101
|
INVALID_NUMBER = '123456789 123456789 123456789 123456789'
|
102
102
|
|
103
103
|
#-----------------------------------------------------------------------------------------------------------------------
|
@@ -243,7 +243,7 @@ describe ActiveModel::Validations::HelperMethods do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should validate a well formatted valid number" do
|
246
|
-
@home.phone_number = "
|
246
|
+
@home.phone_number = "+#{VALID_NUMBER}"
|
247
247
|
@home.should be_valid
|
248
248
|
end
|
249
249
|
|
@@ -272,7 +272,7 @@ describe ActiveModel::Validations::HelperMethods do
|
|
272
272
|
end
|
273
273
|
|
274
274
|
it "should invalidate a bad formatted valid number" do
|
275
|
-
@home.phone_number = "
|
275
|
+
@home.phone_number = "+#{VALID_NUMBER}"
|
276
276
|
@home.should_not be_valid
|
277
277
|
@home.errors.messages.should include(:phone_number => ["is invalid"])
|
278
278
|
end
|
metadata
CHANGED
@@ -1,32 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Joost Hietbrink
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2014-01-28 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: phony
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1
|
21
|
+
version: '2.1'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1
|
29
|
+
version: '2.1'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: countries
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: activesupport
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: activerecord
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ! '>='
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :development
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ! '>='
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -69,6 +78,7 @@ dependencies:
|
|
69
78
|
- !ruby/object:Gem::Dependency
|
70
79
|
name: mongoid
|
71
80
|
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
72
82
|
requirements:
|
73
83
|
- - ! '>='
|
74
84
|
- !ruby/object:Gem::Version
|
@@ -76,6 +86,7 @@ dependencies:
|
|
76
86
|
type: :development
|
77
87
|
prerelease: false
|
78
88
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
79
90
|
requirements:
|
80
91
|
- - ! '>='
|
81
92
|
- !ruby/object:Gem::Version
|
@@ -110,26 +121,27 @@ files:
|
|
110
121
|
homepage: https://github.com/joost/phony_rails
|
111
122
|
licenses:
|
112
123
|
- MIT
|
113
|
-
metadata: {}
|
114
124
|
post_install_message:
|
115
125
|
rdoc_options: []
|
116
126
|
require_paths:
|
117
127
|
- lib
|
118
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
119
130
|
requirements:
|
120
131
|
- - ! '>='
|
121
132
|
- !ruby/object:Gem::Version
|
122
133
|
version: '0'
|
123
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
124
136
|
requirements:
|
125
137
|
- - ! '>='
|
126
138
|
- !ruby/object:Gem::Version
|
127
139
|
version: '0'
|
128
140
|
requirements: []
|
129
141
|
rubyforge_project:
|
130
|
-
rubygems_version:
|
142
|
+
rubygems_version: 1.8.23
|
131
143
|
signing_key:
|
132
|
-
specification_version:
|
144
|
+
specification_version: 3
|
133
145
|
summary: This Gem adds useful methods to your Rails app to validate, display and save
|
134
146
|
phone numbers.
|
135
147
|
test_files:
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
OGNmYjVlMTE5NDBiNGY5Y2MwZGE4ZDVlYzA2M2IxN2M1ZmI1MDBhMg==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZDQ4MTIxNTdlNjVkYzNhNTZjMDQ5NWZiZDc0MTkzY2JkM2MxOWYwOQ==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ODIxZDY3ZDdjY2NiZGU2OGE3NzdjNzI2YzcxYzc5OGQwNGEwZTYwOTA5YWJm
|
10
|
-
MDAyZTc4Njc3NDRkZjU0ODc1NWRiYThjODUzNmI4MDljMzZiNWU1OTQ4YzNm
|
11
|
-
NDMxNGJlMjA5ZWMwMDlkOWJmOTUyNDY0NDM2Mjg0MjcwZWFhMjI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
MzFjNDU4OWQxNTA5ZDFkOWE4M2U5ZTNiN2FmNjE4NzE4NDMyODZlOWQ1OTc4
|
14
|
-
Y2JiMjkyYzkwMTQ5YTA1NjRhOWZlNjhmZDY0ZWU4NGUzODFkNmZkNjRkMjE3
|
15
|
-
ODA5ZWI5ZTRiOTY3MzJjNTJmNDRlNjJjMjg4MmU0MjI2OGY5NzQ=
|