# encoding: utf-8 module LocalPac class GitRepository private attr_reader :storage_path, :data public def initialize(storage_path, compressor_engine = JavaScriptCompressor, file_creator = PacFile) @storage_path = File.expand_path(storage_path) javascript_compressor = compressor_engine.new create unless ::File.exists? @storage_path mutex = Mutex.new mutex.synchronize do @data = pac_files.reduce({}) do |memo, git_file| pac_file = file_creator.new(git_file) javascript_compressor.prepare(pac_file) memo[pac_file.name.to_sym] = pac_file memo end end end def [](name) data[name] end private def create Git.init(storage_path) end def pac_files LocalPac.ui_logger.debug "I'm using the following storage path: \"#{storage_path}\"." files = Git.ls_tree(storage_path).collect do |l| GitFile.new(l, storage_path) end LocalPac.ui_logger.debug "Found the following files: \"#{files.join(", ")}\"." files end end end