Class: PAC::File

Inherits:
Object
  • Object
show all
Defined in:
lib/pac/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ File

Returns a new instance of File.



9
10
11
12
13
# File 'lib/pac/file.rb', line 9

def initialize(source)
  @source = source.dup.freeze
  @context = PAC.runtime.compile(@source)
  @context.include Functions
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/pac/file.rb', line 7

def context
  @context
end

#sourceObject (readonly)

Returns the value of attribute source.



7
8
9
# File 'lib/pac/file.rb', line 7

def source
  @source
end

Instance Method Details

#find(url) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/pac/file.rb', line 15

def find(url)
  uri = URI.parse(url)
  raise ArgumentError, "url is missing host" unless uri.host
  context.call("FindProxyForURL", url, uri.host)
end