validates_email_format_of 1.6.0 → 1.6.1
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 +8 -8
- data/CHANGELOG +3 -0
- data/README.rdoc +2 -0
- data/config/locales/en.yml +3 -1
- data/config/locales/pl.yml +3 -1
- data/lib/validates_email_format_of.rb +14 -9
- data/lib/validates_email_format_of/active_model.rb +1 -1
- data/lib/validates_email_format_of/version.rb +1 -1
- data/spec/validates_email_format_of_spec.rb +17 -9
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWRlNjBlN2VmN2QxNmM4ZWYzODA2YTRmNzNlZjg0MTRlZTlhYjVlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YTg5ZGY1MWEzYWFkYTUzOTVlYzQ0N2FlZGRjNDY0OWY0ZmU2NTA3OA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NDdjMTljZWE2ODRkMTk1MzFmY2FkZDkwMzg4NjUzYmFhMjczMDJlYTcxODI2
|
10
|
+
YjQyNDI0ZmYyZGRhZmYwN2U0MjEyYzVmYzJmZDk1ZDAwMjcwOWZhOGU2YTZl
|
11
|
+
MjdjNmIyNDE3ZjE5YzJmOGI2ZGVjZWRiMWI5ZDFkNjQ1NzRiYjg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTI2Zjg0ZjQ3MzRlZTE2MjEzOTI2NjkwZDUzYjk3MjRmYmYzZDJhNmYzOTUz
|
14
|
+
YWM2MDJiZjkxOGQyNmU2ZDVlZTZiNDMwYWY2YzcwMzU3ZWYyNjVmYmQ1Mzc3
|
15
|
+
MzY1YTgxZmJlMDBiODgyYjVmYmZlZDM0NDhlZGQwYmIyOWM0NTU=
|
data/CHANGELOG
ADDED
data/README.rdoc
CHANGED
@@ -46,6 +46,8 @@ Or in your Gemfile:
|
|
46
46
|
Maximum number of characters allowed in the local part (everything before the '@') (default is 64)
|
47
47
|
:domain_length
|
48
48
|
Maximum number of characters allowed in the domain part (everything after the '@') (default is 255)
|
49
|
+
:generate_message
|
50
|
+
Boolean. Return the I18n key of the error message instead of the error message itself (default is false)
|
49
51
|
:with
|
50
52
|
Specify a custom Regex as the valid email format.
|
51
53
|
:on, :if, :unless, :allow_nil, :allow_blank, :strict
|
data/config/locales/en.yml
CHANGED
data/config/locales/pl.yml
CHANGED
@@ -19,6 +19,15 @@ module ValidatesEmailFormatOf
|
|
19
19
|
@mx.size > 0 ? true : false
|
20
20
|
end
|
21
21
|
|
22
|
+
DEFAULT_MESSAGE = "does not appear to be valid"
|
23
|
+
DEFAULT_MX_MESSAGE = "is not routable"
|
24
|
+
ERROR_MESSAGE_I18N_KEY = :invalid_email_address
|
25
|
+
ERROR_MX_MESSAGE_I18N_KEY = :email_address_not_routable
|
26
|
+
|
27
|
+
def self.default_message
|
28
|
+
defined?(I18n) ? I18n.t(ERROR_MESSAGE_I18N_KEY, :scope => [:activemodel, :errors, :messages], :default => DEFAULT_MESSAGE) : DEFAULT_MESSAGE
|
29
|
+
end
|
30
|
+
|
22
31
|
# Validates whether the specified value is a valid email address. Returns nil if the value is valid, otherwise returns an array
|
23
32
|
# containing one or more validation error messages.
|
24
33
|
#
|
@@ -29,18 +38,14 @@ module ValidatesEmailFormatOf
|
|
29
38
|
# * <tt>with</tt> The regex to use for validating the format of the email address (deprecated)
|
30
39
|
# * <tt>local_length</tt> Maximum number of characters allowed in the local part (default is 64)
|
31
40
|
# * <tt>domain_length</tt> Maximum number of characters allowed in the domain part (default is 255)
|
32
|
-
|
33
|
-
DEFAULT_MX_MESSAGE = "is not routable"
|
34
|
-
def self.default_message
|
35
|
-
defined?(I18n) ? I18n.t(:invalid_email_address, :scope => [:activemodel, :errors, :messages], :default => DEFAULT_MESSAGE) : DEFAULT_MESSAGE
|
36
|
-
end
|
37
|
-
|
41
|
+
# * <tt>generate_message</tt> Return the I18n key of the error message instead of the error message itself (default is false)
|
38
42
|
def self.validate_email_format(email, options={})
|
39
|
-
default_options = { :message => default_message,
|
43
|
+
default_options = { :message => options[:generate_message] ? ERROR_MESSAGE_I18N_KEY : default_message,
|
40
44
|
:check_mx => false,
|
41
|
-
:mx_message => defined?(I18n) ? I18n.t(
|
45
|
+
:mx_message => options[:generate_message] ? ERROR_MX_MESSAGE_I18N_KEY : (defined?(I18n) ? I18n.t(ERROR_MX_MESSAGE_I18N_KEY, :scope => [:activemodel, :errors, :messages], :default => DEFAULT_MX_MESSAGE) : DEFAULT_MX_MESSAGE),
|
42
46
|
:domain_length => 255,
|
43
|
-
:local_length => 64
|
47
|
+
:local_length => 64,
|
48
|
+
:generate_message => false
|
44
49
|
}
|
45
50
|
opts = options.merge(default_options) {|key, old, new| old} # merge the default options into the specified options, retaining all specified options
|
46
51
|
|
@@ -9,7 +9,7 @@ module ActiveModel
|
|
9
9
|
module Validations
|
10
10
|
class EmailFormatValidator < EachValidator
|
11
11
|
def validate_each(record, attribute, value)
|
12
|
-
(ValidatesEmailFormatOf::validate_email_format(value, options) || []).each do |error|
|
12
|
+
(ValidatesEmailFormatOf::validate_email_format(value, options.merge(:generate_message => true)) || []).each do |error|
|
13
13
|
record.errors.add(attribute, error)
|
14
14
|
end
|
15
15
|
end
|
@@ -205,17 +205,21 @@ describe ValidatesEmailFormatOf do
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
describe "i18n" do
|
208
|
-
before(:each)
|
208
|
+
before(:each) do
|
209
|
+
allow(I18n.config).to receive(:locale).and_return(locale)
|
210
|
+
end
|
209
211
|
describe "present locale" do
|
210
212
|
let(:locale) { :pl }
|
211
213
|
describe email do
|
212
214
|
it { should have_errors_on_email.because("jest nieosiągalny") }
|
213
215
|
end
|
214
216
|
end
|
215
|
-
|
216
|
-
let(:locale) { :ir }
|
217
|
+
unless defined?(ActiveModel)
|
217
218
|
describe email do
|
218
|
-
|
219
|
+
let(:locale) { :ir }
|
220
|
+
describe email do
|
221
|
+
it { should have_errors_on_email.because("is not routable") }
|
222
|
+
end
|
219
223
|
end
|
220
224
|
end
|
221
225
|
end
|
@@ -262,17 +266,21 @@ describe ValidatesEmailFormatOf do
|
|
262
266
|
end
|
263
267
|
|
264
268
|
describe "i18n" do
|
265
|
-
before(:each)
|
269
|
+
before(:each) do
|
270
|
+
allow(I18n.config).to receive(:locale).and_return(locale)
|
271
|
+
end
|
266
272
|
describe "present locale" do
|
267
273
|
let(:locale) { :pl }
|
268
274
|
describe "invalid@exmaple." do
|
269
275
|
it { should have_errors_on_email.because("nieprawidłowy adres e-mail") }
|
270
276
|
end
|
271
277
|
end
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
278
|
+
unless defined?(ActiveModel)
|
279
|
+
describe "missing locale" do
|
280
|
+
let(:locale) { :ir }
|
281
|
+
describe "invalid@exmaple." do
|
282
|
+
it { should have_errors_on_email.because("does not appear to be valid") }
|
283
|
+
end
|
276
284
|
end
|
277
285
|
end
|
278
286
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validates_email_format_of
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Dunae
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-08
|
12
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: i18n
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- .gitignore
|
65
65
|
- .rspec
|
66
66
|
- .travis.yml
|
67
|
+
- CHANGELOG
|
67
68
|
- Gemfile
|
68
69
|
- MIT-LICENSE
|
69
70
|
- README.rdoc
|