Sha256: 4c5f488d173899acb79ba7faa176a6e79669bdd8f1db5fae21cfcc9d71172ccb

Contents?: true

Size: 1.32 KB

Versions: 27

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8
module ProxyPacRb
  # Dump Proxy pac to file system
  class ProxyPacDumper
    private

    attr_reader :type, :dumpers

    public

    def initialize
      @dumpers = Hash.new { ProxyPacStringDumper.new }
      @dumpers[:template] = ProxyPacTemplateDumper.new
      @dumpers[:string] = ProxyPacStringDumper.new
    end

    def dump(proxy_pac, type:)
      dumpers[type].dump(proxy_pac)
    end
  end

  # Dump string to file
  class ProxyPacStringDumper
    private

    attr_reader :default_file_name

    public

    def initialize
      @default_file_name = 'proxy.pac'
    end

    def dump(proxy_pac)
      ::File.write(default_file_name, proxy_pac.content)
    end
  end

  # Dump proxy pac based on template
  class ProxyPacTemplateDumper
    def dump(proxy_pac)
      ::File.write(output_path(proxy_pac.source), proxy_pac.content)
    end

    private

    def in_extension
      '.in'
    end

    def out_extension
      '.out'
    end

    def output_path(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
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
proxy_pac_rb-0.9.1 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.8.2 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.8.1 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.8.0 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.7.0 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.9 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.8 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.7 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.5 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.4 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.3 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.2 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.1 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.6.0 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.5.10 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.5.9 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.5.8 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.5.7 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.5.6 lib/proxy_pac_rb/proxy_pac_dumper.rb
proxy_pac_rb-0.5.5 lib/proxy_pac_rb/proxy_pac_dumper.rb