Sha256: 431cef66b77b332b17675a0a47ad66f802b8a70cd9524cffcfbc7123f855f4fb

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

module LocalPac
  class PacManager

    private

    attr_reader :cache, :null_file, :paths, :creator

    public

    def initialize(paths = default_paths, creator = PacFile)
      @paths   = Array(paths)
      @creator = creator
      @cache = ActiveSupport::Cache::MemoryStore.new
      @null_file = proc { NullPacFile.new }
    end

    def find(name)
      name = File.basename(name, '.pac').to_sym

      cache.fetch(name) do
        pac_files.find(null_file) { |f| f.name == name }
      end
    end

    private

    def pac_files
      paths.reduce([]) do |memo, path|
        memo.concat Dir.glob(File.join(path, '*.pac')).collect { |f| creator.new(f) }
      end
    end

    def default_paths
      [
        File.expand_path(File.join(ENV['HOME'], '.config', 'pacfiles')),
        File.expand_path(File.join(ENV['HOME'], '.pacfiles')),
        File.expand_path('../../../files', __FILE__),
      ]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
local_pac-0.0.6 lib/local_pac/pac_manager.rb