email_parser 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ea1a1988ef62756778d13c2151fbe9ca21d7543054d97bda23deafce3603e3c
4
- data.tar.gz: d8f123352b5bfcaacc4b44e205ce5a5fe27ce3212344e92a9dff1f54454d45c2
3
+ metadata.gz: e6fdf94736e0bed8e9c09506d0547592fd2504407c7956ebfbf44a803465ac14
4
+ data.tar.gz: d9fb9bbccb6c65349f57e9cd9ac986f7300f16afe0b3b7a0e69e0a1439be97d8
5
5
  SHA512:
6
- metadata.gz: 7a372f31baebd0855edffef741e4fbf9235d9620e8f3f935618be4d7f05aaf2963f427fbae01f6c49cafe0fbc0ede544fce24bc70f60a08dec5fc84a3a59bfa4
7
- data.tar.gz: 9957b4f39069be665c645074e4afc3527ded5da57c87bb30ca9da8580697f478bbb8319b08eca9d7306ad2b8c61bf5113839d8986d2b668d1b6e81af1095d3dc
6
+ metadata.gz: df1af5ba4a855b0dc9e4fb63b96752fa5ac5e8a952581d984eb330400a02afe33334e211ca229017b0fe78aec986119d3c919e6720702f4baf6624107cf52bbe
7
+ data.tar.gz: dcd8297572e7a7603d4a34d6a7cd0cf2ced9d0f6e0a6d253530202cebbdc257ab57c64f23657de332fe619b43ecae0e20706176f58595954d7bf8fdea3c4f724
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # v0.1.2
2
+
3
+ - support default validator options (:if etc.)
4
+
1
5
  # v0.1.1
2
6
 
3
7
  - add option to allow domain beginning with number
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- email_parser (0.1.1)
4
+ email_parser (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/email_parser.rb CHANGED
@@ -21,7 +21,9 @@ class EmailParser
21
21
  ")+",
22
22
  )
23
23
 
24
- attr_reader :allow_address_literal, :allow_domain_label_begin_with_number, :allow_dot_sequence_in_local, :allow_local_begin_with_dot, :allow_local_end_with_dot
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(allow_address_literal: false, allow_domain_label_begin_with_number: false, allow_dot_sequence_in_local: false, allow_local_begin_with_dot: false, allow_local_end_with_dot: false)
35
- @allow_address_literal = allow_address_literal
36
- raise NotImplementedError("Sorry, `allow_address_literal == true` is not supported yet") if allow_address_literal
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
- @allow_domain_label_begin_with_number = allow_domain_label_begin_with_number
39
- @allow_dot_sequence_in_local = allow_dot_sequence_in_local
40
- @allow_local_begin_with_dot = allow_local_begin_with_dot
41
- @allow_local_end_with_dot = allow_local_end_with_dot
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.dup
16
- @allow_nil = parser_options.delete(:allow_nil)
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
@@ -1,3 +1,3 @@
1
1
  class EmailParser
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: email_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - labocho