email_parser 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/email_parser.rb +14 -8
- data/lib/email_parser/validator.rb +4 -5
- data/lib/email_parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6fdf94736e0bed8e9c09506d0547592fd2504407c7956ebfbf44a803465ac14
|
4
|
+
data.tar.gz: d9fb9bbccb6c65349f57e9cd9ac986f7300f16afe0b3b7a0e69e0a1439be97d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df1af5ba4a855b0dc9e4fb63b96752fa5ac5e8a952581d984eb330400a02afe33334e211ca229017b0fe78aec986119d3c919e6720702f4baf6624107cf52bbe
|
7
|
+
data.tar.gz: dcd8297572e7a7603d4a34d6a7cd0cf2ced9d0f6e0a6d253530202cebbdc257ab57c64f23657de332fe619b43ecae0e20706176f58595954d7bf8fdea3c4f724
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/email_parser.rb
CHANGED
@@ -21,7 +21,9 @@ class EmailParser
|
|
21
21
|
")+",
|
22
22
|
)
|
23
23
|
|
24
|
-
|
24
|
+
OPTIONS = %i(allow_address_literal allow_domain_label_begin_with_number allow_dot_sequence_in_local allow_local_begin_with_dot allow_local_end_with_dot).freeze
|
25
|
+
|
26
|
+
attr_reader(*OPTIONS)
|
25
27
|
|
26
28
|
def self.parse(src, **options)
|
27
29
|
new(**options).parse(src)
|
@@ -31,14 +33,18 @@ class EmailParser
|
|
31
33
|
new(**options).valid?(src)
|
32
34
|
end
|
33
35
|
|
34
|
-
def initialize(
|
35
|
-
|
36
|
-
|
36
|
+
def initialize(options = {})
|
37
|
+
options = options.dup
|
38
|
+
OPTIONS.each do |k|
|
39
|
+
v = options.delete(k)
|
40
|
+
instance_variable_set("@#{k}", v.nil? ? false : v)
|
41
|
+
end
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
43
|
+
unless options.empty?
|
44
|
+
raise "Unknown EmailParser option: #{options.inspect}"
|
45
|
+
end
|
46
|
+
|
47
|
+
raise NotImplementedError("Sorry, `allow_address_literal == true` is not supported yet") if allow_address_literal
|
42
48
|
end
|
43
49
|
|
44
50
|
def valid?(src)
|
@@ -2,8 +2,6 @@ require "active_model"
|
|
2
2
|
require "email_parser"
|
3
3
|
|
4
4
|
class EmailValidator < ActiveModel::EachValidator
|
5
|
-
attr_reader :allow_nil
|
6
|
-
|
7
5
|
class << self
|
8
6
|
attr_accessor :default_parser_options
|
9
7
|
end
|
@@ -12,14 +10,15 @@ class EmailValidator < ActiveModel::EachValidator
|
|
12
10
|
|
13
11
|
def initialize(*_args)
|
14
12
|
super
|
15
|
-
parser_options = options.
|
16
|
-
|
13
|
+
parser_options = options.each_with_object({}) do |(k, v), h|
|
14
|
+
h[k] = v if EmailParser::OPTIONS.include?(k)
|
15
|
+
end
|
17
16
|
@parser = EmailParser.new(**self.class.default_parser_options.merge(parser_options))
|
18
17
|
end
|
19
18
|
|
20
19
|
def validate_each(record, attribute, value)
|
21
20
|
if value.nil?
|
22
|
-
return if allow_nil
|
21
|
+
return if options[:allow_nil]
|
23
22
|
|
24
23
|
record.errors.add(attribute, :blank)
|
25
24
|
return
|
data/lib/email_parser/version.rb
CHANGED