-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathconfig.rb
108 lines (98 loc) · 2.13 KB
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
module EmailVeracity
module Config
DEFAULT_OPTIONS = {
:whitelist => %w[
aol.com
gmail.com
hotmail.com
me.com
mac.com
msn.com
rogers.com
sympatico.ca
yahoo.com
telus.com
sprint.com
sprint.ca ],
:blacklist => %w[
dodgeit.com
mintemail.com
mintemail.uni.cc
1mintemail.mooo.com
spammotel.com
trashmail.net ],
:valid_pattern => %r{
^
(
[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+
\.
)
*
[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+
@
(
(
(
(
(
[a-z0-9]{1}
[a-z0-9\-]{0,62}
[a-z0-9]{1}
)
|
[a-z]
)
\.
)+
[a-z]{2,6}
)
|
(
\d{1,3}
\.
){3}
\d{1,3}
(
\:\d{1,5}
)?
)
$
}xi,
:must_include => [],
:timeout => 2,
:skip_lookup => false,
:enforce_blacklist => false,
:enforce_whitelist => true }
@options = DEFAULT_OPTIONS.clone
def [](key)
@options[key.to_sym]
end
def []=(key, value)
@options[key.to_sym] = value
end
def options
@options
end
def options=(options)
unless options.is_a?(Hash)
raise ArgumentError, "options must be a Hash not #{options.class}"
end
@options = options
end
def update(options)
unless options.is_a?(Hash)
raise ArgumentError, "options must be a Hash not #{options.class}"
end
@options.update(options)
end
def enforced_record?(record)
return unless @options[:must_include].is_a?(Array)
@options[:must_include].any? { |i| i.to_s == record.to_s }
end
def revert!
@options = DEFAULT_OPTIONS.clone
end
module_function :[], :[]=, :options, :options=, :update, :enforced_record?,
:revert!
end
end