Class: SocksHandler::Rule
- Inherits:
-
Object
- Object
- SocksHandler::Rule
show all
- Defined in:
- lib/socks_handler/rule.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil) ⇒ Rule
Returns a new instance of Rule.
28
29
30
31
32
33
34
|
# File 'lib/socks_handler/rule.rb', line 28
def initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil)
@host = host
@port = port
@username = username
@password = password
self.host_patterns = host_patterns
end
|
Instance Attribute Details
#host ⇒ String?
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
|
# File 'lib/socks_handler/rule.rb', line 14
class Rule
attr_reader :host, :port, :username, :password, :host_patterns
def self.new(**kwargs)
raise "Rule is an abstract class" if self == Rule
super
end
def initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil)
@host = host
@port = port
@username = username
@password = password
self.host_patterns = host_patterns
end
def direct
raise NotImplementedError
end
def host_patterns=(value)
raise ArgumentError, "host_patterns is not an array" unless value.is_a?(Array)
@host_patterns = value.frozen? ? value : value.dup.freeze
@remote_host_pattern_regex = Regexp.union(convert_regexps(value))
value
end
def match?(remote_host)
@remote_host_pattern_regex.match?(remote_host)
end
private
def convert_regexps(value)
value.map do |v|
v.is_a?(Regexp) ? v : Regexp.new("\\A#{Regexp.escape(v)}\\z")
end
end
end
|
#host_patterns ⇒ Array<String, Regexp>
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
|
# File 'lib/socks_handler/rule.rb', line 14
class Rule
attr_reader :host, :port, :username, :password, :host_patterns
def self.new(**kwargs)
raise "Rule is an abstract class" if self == Rule
super
end
def initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil)
@host = host
@port = port
@username = username
@password = password
self.host_patterns = host_patterns
end
def direct
raise NotImplementedError
end
def host_patterns=(value)
raise ArgumentError, "host_patterns is not an array" unless value.is_a?(Array)
@host_patterns = value.frozen? ? value : value.dup.freeze
@remote_host_pattern_regex = Regexp.union(convert_regexps(value))
value
end
def match?(remote_host)
@remote_host_pattern_regex.match?(remote_host)
end
private
def convert_regexps(value)
value.map do |v|
v.is_a?(Regexp) ? v : Regexp.new("\\A#{Regexp.escape(v)}\\z")
end
end
end
|
#password ⇒ String?
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
|
# File 'lib/socks_handler/rule.rb', line 14
class Rule
attr_reader :host, :port, :username, :password, :host_patterns
def self.new(**kwargs)
raise "Rule is an abstract class" if self == Rule
super
end
def initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil)
@host = host
@port = port
@username = username
@password = password
self.host_patterns = host_patterns
end
def direct
raise NotImplementedError
end
def host_patterns=(value)
raise ArgumentError, "host_patterns is not an array" unless value.is_a?(Array)
@host_patterns = value.frozen? ? value : value.dup.freeze
@remote_host_pattern_regex = Regexp.union(convert_regexps(value))
value
end
def match?(remote_host)
@remote_host_pattern_regex.match?(remote_host)
end
private
def convert_regexps(value)
value.map do |v|
v.is_a?(Regexp) ? v : Regexp.new("\\A#{Regexp.escape(v)}\\z")
end
end
end
|
#port ⇒ Integer?
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
|
# File 'lib/socks_handler/rule.rb', line 14
class Rule
attr_reader :host, :port, :username, :password, :host_patterns
def self.new(**kwargs)
raise "Rule is an abstract class" if self == Rule
super
end
def initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil)
@host = host
@port = port
@username = username
@password = password
self.host_patterns = host_patterns
end
def direct
raise NotImplementedError
end
def host_patterns=(value)
raise ArgumentError, "host_patterns is not an array" unless value.is_a?(Array)
@host_patterns = value.frozen? ? value : value.dup.freeze
@remote_host_pattern_regex = Regexp.union(convert_regexps(value))
value
end
def match?(remote_host)
@remote_host_pattern_regex.match?(remote_host)
end
private
def convert_regexps(value)
value.map do |v|
v.is_a?(Regexp) ? v : Regexp.new("\\A#{Regexp.escape(v)}\\z")
end
end
end
|
#username ⇒ String?
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
|
# File 'lib/socks_handler/rule.rb', line 14
class Rule
attr_reader :host, :port, :username, :password, :host_patterns
def self.new(**kwargs)
raise "Rule is an abstract class" if self == Rule
super
end
def initialize(host_patterns:, host: nil, port: nil, username: nil, password: nil)
@host = host
@port = port
@username = username
@password = password
self.host_patterns = host_patterns
end
def direct
raise NotImplementedError
end
def host_patterns=(value)
raise ArgumentError, "host_patterns is not an array" unless value.is_a?(Array)
@host_patterns = value.frozen? ? value : value.dup.freeze
@remote_host_pattern_regex = Regexp.union(convert_regexps(value))
value
end
def match?(remote_host)
@remote_host_pattern_regex.match?(remote_host)
end
private
def convert_regexps(value)
value.map do |v|
v.is_a?(Regexp) ? v : Regexp.new("\\A#{Regexp.escape(v)}\\z")
end
end
end
|
Class Method Details
.new(**kwargs) ⇒ Rule
18
19
20
21
|
# File 'lib/socks_handler/rule.rb', line 18
def self.new(**kwargs)
raise "Rule is an abstract class" if self == Rule
super
end
|
Instance Method Details
#direct ⇒ Boolean
37
38
39
|
# File 'lib/socks_handler/rule.rb', line 37
def direct
raise NotImplementedError
end
|
#match?(remote_host) ⇒ Boolean
52
53
54
|
# File 'lib/socks_handler/rule.rb', line 52
def match?(remote_host)
@remote_host_pattern_regex.match?(remote_host)
end
|