Class: ProxyPacRb::ProxyPacFile

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/proxy_pac_rb/proxy_pac_file.rb

Overview

Pac file

Instance Attribute Summary collapse

Instance Method Summary collapse

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.message    = source.message
    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

#contentObject

Returns the value of attribute content


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def content
  @content
end

#javascriptObject

Returns the value of attribute javascript


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def javascript
  @javascript
end

#messageObject

Returns the value of attribute message


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def message
  @message
end

#parsableObject

Returns the value of attribute parsable


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def parsable
  @parsable
end

#readableObject

Returns the value of attribute readable


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def readable
  @readable
end

#sourceObject

Returns the value of attribute source


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def source
  @source
end

#typeObject

Returns the value of attribute type


7
8
9
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 7

def type
  @type
end

#validObject

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

Returns:

  • (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

Raises:


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: #{message}. Stopping here." unless readable?
    raise ProxyPacInvalidError, "The proxy.pac \"#{source}\" is not valid: #{message}. 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: #{message}. 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

Returns:

  • (Boolean)

51
52
53
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 51

def javascript?
  !javascript.nil?
end

#parsable?Boolean

Returns:

  • (Boolean)

47
48
49
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 47

def parsable?
  parsable == true
end

#readable?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 39

def readable?
  readable == true
end

#type?(t) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 35

def type?(t)
  type == t
end

#valid?Boolean

Returns:

  • (Boolean)

43
44
45
# File 'lib/proxy_pac_rb/proxy_pac_file.rb', line 43

def valid?
  valid == true
end