Class: ProxyPacRb::ProxyPacFile
- Inherits:
-
Object
- Object
- ProxyPacRb::ProxyPacFile
- Includes:
- Comparable
- Defined in:
- lib/proxy_pac_rb/proxy_pac_file.rb
Overview
Pac file
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#javascript ⇒ Object
Returns the value of attribute javascript.
-
#message ⇒ Object
Returns the value of attribute message.
-
#parsable ⇒ Object
Returns the value of attribute parsable.
-
#readable ⇒ Object
Returns the value of attribute readable.
-
#source ⇒ Object
Returns the value of attribute source.
-
#type ⇒ Object
Returns the value of attribute type.
-
#valid ⇒ Object
Returns the value of attribute valid.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #content? ⇒ Boolean
- #find(url, fail_safe: true) ⇒ Object
-
#initialize(source:) ⇒ ProxyPacFile
constructor
A new instance of ProxyPacFile.
- #javascript? ⇒ Boolean
- #parsable? ⇒ Boolean
- #readable? ⇒ Boolean
- #type?(t) ⇒ Boolean
- #valid? ⇒ Boolean
Constructor Details
#initialize(source:) ⇒ ProxyPacFile
Returns a new instance of ProxyPacFile.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 9 def initialize(source:) if source.is_a? ProxyPacFile self.valid = source.valid self.type = source.type self. = source. self.readable = source.readable self.javascript = source.javascript self.parsable = source.parsable self.content = source.content self.source = source.source else @source = source @valid = false @parsable = false @readable = false end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def content @content end |
#javascript ⇒ Object
Returns the value of attribute javascript.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def javascript @javascript end |
#message ⇒ Object
Returns the value of attribute message.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def @message end |
#parsable ⇒ Object
Returns the value of attribute parsable.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def parsable @parsable end |
#readable ⇒ Object
Returns the value of attribute readable.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def readable @readable end |
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def source @source end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def type @type end |
#valid ⇒ Object
Returns the value of attribute valid.
7 8 9 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7 def valid @valid end |
Instance Method Details
#<=>(other) ⇒ Object
31 32 33 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 31 def <=>(other) content <=> other.content end |
#content? ⇒ Boolean
27 28 29 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 27 def content? !@content.nil? end |
#find(url, fail_safe: true) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 55 def find(url, fail_safe: true) if fail_safe == true raise ProxyPacInvalidError, "The proxy.pac \"#{source}\" is not readable: #{}. Stopping here." unless readable? raise ProxyPacInvalidError, "The proxy.pac \"#{source}\" is not valid: #{}. Stopping here." unless valid? raise ProxyPacInvalidError, "The proxy.pac \"#{source}\" is could not be parsed. There's no compiled javascript to use to lookup a url: #{}. Stopping here." unless javascript? end uri = Addressable::URI.heuristic_parse(url) if hostname?(url) uri.scheme = 'http' uri.path = '/' uri.host = url end raise UrlInvalidError, 'url is missing host' unless uri.host javascript.FindProxyForURL(uri.to_s, uri.host) end |
#javascript? ⇒ Boolean
51 52 53 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 51 def javascript? !javascript.nil? end |
#parsable? ⇒ Boolean
47 48 49 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 47 def parsable? parsable == true end |
#readable? ⇒ Boolean
39 40 41 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 39 def readable? readable == true end |
#type?(t) ⇒ Boolean
35 36 37 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 35 def type?(t) type == t end |
#valid? ⇒ Boolean
43 44 45 |
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 43 def valid? valid == true end |