Sha256: 6f8c827780852fbc1e821f67026d3d87a9ed9abb2daedea9ae9dbae2f0229993

Contents?: true

Size: 1.57 KB

Versions: 23

Compression:

Stored size: 1.57 KB

Contents

# encoding: utf-8
module ProxyPacRb
  # Template for proxy pac
  class ProxyPacTemplate
    private

    attr_reader :path, :compressed_content

    public

    attr_writer :compressed_content

    def initialize(path)
      @path = path
    end

    def write
      ::File.write(output_path, compressed_content)
    end

    def compress_me(compressor)
      compressor.compress(self)
    end

    def raw_content
      read_proxy_pac(input_path)
    end

    def input_path
      if ::File.exist?(path.gsub(/#{in_extension}*$/, '') + in_extension)
        return path.gsub(/#{in_extension}*$/, '') + in_extension
      elsif ::File.exist? path
        return path
      else
        fail Errno::ENOENT, "Both paths \"#{path.gsub(/#{in_extension}*$/, '') + in_extension}\" and \"#{path}\" do not exist."
      end
    end

    private

    def in_extension
      '.in'
    end

    def out_extension
      '.out'
    end

    def output_path
      if ::File.exist?(path.gsub(/#{in_extension}*$/, '') + in_extension)
        return path.gsub(/#{in_extension}*$/, '')
      elsif ::File.exist? path
        return path + out_extension
      else
        fail Errno::ENOENT, "Both paths \"#{path.gsub(/#{in_extension}*$/, '') + in_extension}\" and \"#{path}\" do not exist."
      end
    end

    def read_proxy_pac(path)
      uri = Addressable::URI.parse(path)

      uri.path = ::File.expand_path(uri.path) if uri.host.nil?

      ENV.delete 'HTTP_PROXY'
      ENV.delete 'HTTPS_PROXY'
      ENV.delete 'http_proxy'
      ENV.delete 'https_proxy'

      open(uri, proxy: false).read
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
proxy_pac_rb-0.6.8 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.7 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.5 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.4 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.3 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.2 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.1 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.6.0 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.10 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.9 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.8 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.7 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.6 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.5 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.4 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.3 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.2 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.1 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.5.0 lib/proxy_pac_rb/proxy_pac_template.rb
proxy_pac_rb-0.4.2 lib/proxy_pac_rb/proxy_pac_template.rb