phony_rails 0.1.7 → 0.1.8
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 +1 -1
- data/README.md +5 -0
- data/lib/phony_rails.rb +10 -5
- data/lib/phony_rails/locales/en.yml +6 -0
- data/lib/phony_rails/locales/fr.yml +6 -0
- data/lib/phony_rails/version.rb +1 -1
- data/lib/validators/phony_validator.rb +1 -1
- data/spec/lib/validators/phony_validator_spec.rb +18 -0
- metadata +73 -66
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -62,6 +62,8 @@ so we can use:
|
|
62
62
|
validates_plausible_phone :phone_number, :without => /^\+\d+/
|
63
63
|
validates_plausible_phone :phone_number, :presence => true, :with => /^\+\d+/
|
64
64
|
|
65
|
+
the i18n key is `:improbable_phone`
|
66
|
+
|
65
67
|
### Display / Views
|
66
68
|
|
67
69
|
In your views use:
|
@@ -76,6 +78,9 @@ Say you want to find a record by a phone number. Best is to normalize user input
|
|
76
78
|
|
77
79
|
## Changelog
|
78
80
|
|
81
|
+
0.1.8
|
82
|
+
* Improved validation methods by ddidier.
|
83
|
+
|
79
84
|
0.1.6
|
80
85
|
* Added :as option to phony_normalize.
|
81
86
|
|
data/lib/phony_rails.rb
CHANGED
@@ -40,8 +40,8 @@ module PhonyRails
|
|
40
40
|
end
|
41
41
|
|
42
42
|
module InstanceMethods
|
43
|
-
|
44
|
-
|
43
|
+
|
44
|
+
private
|
45
45
|
|
46
46
|
# This methods sets the attribute to the normalized version.
|
47
47
|
# It also adds the country_code (number), eg. 31 for NL numbers.
|
@@ -70,7 +70,7 @@ module PhonyRails
|
|
70
70
|
attributes.each do |attribute|
|
71
71
|
raise ArgumentError, "No attribute #{attribute} found on #{self.class.name} (PhonyRails)" if not self.attribute_method?(attribute)
|
72
72
|
# Add before validation that saves a normalized version of the phone number
|
73
|
-
self.before_validation do
|
73
|
+
self.before_validation do
|
74
74
|
set_phony_normalized_numbers(attributes, options)
|
75
75
|
end
|
76
76
|
end
|
@@ -80,7 +80,7 @@ module PhonyRails
|
|
80
80
|
# phony_normalized_method :fax_number, :default_country_code => 'US'
|
81
81
|
# Creates a normalized_fax_number method.
|
82
82
|
def phony_normalized_method(*attributes)
|
83
|
-
main_options = attributes.last.is_a?(Hash) ? attributes.pop : {}
|
83
|
+
main_options = attributes.last.is_a?(Hash) ? attributes.pop : {}
|
84
84
|
main_options.assert_valid_keys :country_code, :default_country_code
|
85
85
|
attributes.each do |attribute|
|
86
86
|
raise StandardError, "Instance method normalized_#{attribute} already exists on #{self.name} (PhonyRails)" if self.instance_methods.include?(:"normalized_#{attribute}")
|
@@ -97,4 +97,9 @@ module PhonyRails
|
|
97
97
|
end
|
98
98
|
|
99
99
|
end
|
100
|
-
|
100
|
+
|
101
|
+
ActiveRecord::Base.extend PhonyRails::ActiveRecordExtension
|
102
|
+
|
103
|
+
Dir["#{File.dirname(__FILE__)}/phony_rails/locales/*.yml"].each do |file|
|
104
|
+
I18n.load_path << file
|
105
|
+
end
|
data/lib/phony_rails/version.rb
CHANGED
@@ -6,7 +6,7 @@ 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
|
-
record.errors
|
9
|
+
record.errors.add(attribute, options[:message] || :improbable_phone) if not Phony.plausible?(value)
|
10
10
|
end
|
11
11
|
|
12
12
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
#-----------------------------------------------------------------------------------------------------------------------
|
@@ -81,6 +82,7 @@ end
|
|
81
82
|
# Tests
|
82
83
|
#-----------------------------------------------------------------------------------------------------------------------
|
83
84
|
|
85
|
+
I18n.locale = :en
|
84
86
|
VALID_NUMBER = '123456789'
|
85
87
|
INVALID_NUMBER = '123456789 123456789 123456789 123456789'
|
86
88
|
|
@@ -109,6 +111,22 @@ describe PhonyPlausibleValidator do
|
|
109
111
|
@home.errors.messages.should include(:phone_number => ["is an invalid number"])
|
110
112
|
end
|
111
113
|
|
114
|
+
it "should translate the error message in english" do
|
115
|
+
I18n.with_locale(:en) do
|
116
|
+
@home.phone_number = INVALID_NUMBER
|
117
|
+
@home.valid?
|
118
|
+
@home.errors.messages.should include(:phone_number => ["is an invalid number"])
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should translate the error message in french" do
|
123
|
+
I18n.with_locale(:fr) do
|
124
|
+
@home.phone_number = INVALID_NUMBER
|
125
|
+
@home.valid?
|
126
|
+
@home.errors.messages.should include(:phone_number => ["est un numéro invalide"])
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
112
130
|
end
|
113
131
|
end
|
114
132
|
|
metadata
CHANGED
@@ -1,72 +1,73 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony_rails
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Joost Hietbrink
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
16
|
+
|
17
|
+
date: 2012-07-30 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: phony
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 1.7.7
|
22
|
-
type: :runtime
|
23
22
|
prerelease: false
|
24
|
-
|
25
|
-
|
26
|
-
requirements:
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
27
25
|
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 7
|
30
|
+
- 7
|
29
31
|
version: 1.7.7
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: countries
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 0.8.2
|
38
32
|
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: countries
|
39
36
|
prerelease: false
|
40
|
-
|
41
|
-
|
42
|
-
requirements:
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
43
39
|
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 8
|
44
|
+
- 2
|
45
45
|
version: 0.8.2
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: activerecord
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '3.0'
|
54
46
|
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activerecord
|
55
50
|
prerelease: false
|
56
|
-
|
57
|
-
|
58
|
-
requirements:
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
59
53
|
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 3
|
57
|
+
- 0
|
58
|
+
version: "3.0"
|
59
|
+
type: :runtime
|
60
|
+
version_requirements: *id003
|
61
|
+
description: This Gem adds useful methods to your Rails app to validate, display and save phone numbers.
|
62
|
+
email:
|
65
63
|
- joost@joopp.com
|
66
64
|
executables: []
|
65
|
+
|
67
66
|
extensions: []
|
67
|
+
|
68
68
|
extra_rdoc_files: []
|
69
|
-
|
69
|
+
|
70
|
+
files:
|
70
71
|
- .gitignore
|
71
72
|
- .rspec
|
72
73
|
- Gemfile
|
@@ -76,6 +77,8 @@ files:
|
|
76
77
|
- README.md
|
77
78
|
- Rakefile
|
78
79
|
- lib/phony_rails.rb
|
80
|
+
- lib/phony_rails/locales/en.yml
|
81
|
+
- lib/phony_rails/locales/fr.yml
|
79
82
|
- lib/phony_rails/string_extensions.rb
|
80
83
|
- lib/phony_rails/version.rb
|
81
84
|
- lib/validators/phony_validator.rb
|
@@ -83,33 +86,37 @@ files:
|
|
83
86
|
- spec/lib/phony_rails_spec.rb
|
84
87
|
- spec/lib/validators/phony_validator_spec.rb
|
85
88
|
- spec/spec_helper.rb
|
89
|
+
has_rdoc: true
|
86
90
|
homepage: https://github.com/joost/phony_rails
|
87
91
|
licenses: []
|
92
|
+
|
88
93
|
post_install_message:
|
89
94
|
rdoc_options: []
|
90
|
-
|
95
|
+
|
96
|
+
require_paths:
|
91
97
|
- lib
|
92
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
requirements:
|
101
|
-
- -
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 0
|
111
|
+
version: "0"
|
104
112
|
requirements: []
|
113
|
+
|
105
114
|
rubyforge_project:
|
106
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.3.6
|
107
116
|
signing_key:
|
108
117
|
specification_version: 3
|
109
|
-
summary: This Gem adds useful methods to your Rails app to validate, display and save
|
110
|
-
|
111
|
-
test_files:
|
118
|
+
summary: This Gem adds useful methods to your Rails app to validate, display and save phone numbers.
|
119
|
+
test_files:
|
112
120
|
- spec/lib/phony_rails_spec.rb
|
113
121
|
- spec/lib/validators/phony_validator_spec.rb
|
114
122
|
- spec/spec_helper.rb
|
115
|
-
has_rdoc:
|