Sha256: 33f4209574a16246f37ebff2298b656cf8d7bea0882733e42c4fe06a79a3c319

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

# 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 = 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
      Dir.chdir(storage_path) do
        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)
        end

        LocalPac.ui_logger.debug "Found the following files: \"#{files.join(", ")}\"."
        files
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
local_pac-0.1.9 lib/local_pac/git_repository.rb
local_pac-0.1.8 lib/local_pac/git_repository.rb
local_pac-0.1.7 lib/local_pac/git_repository.rb
local_pac-0.1.6 lib/local_pac/git_repository.rb
local_pac-0.1.5 lib/local_pac/git_repository.rb
local_pac-0.1.4 lib/local_pac/git_repository.rb
local_pac-0.1.3 lib/local_pac/git_repository.rb
local_pac-0.1.2 lib/local_pac/git_repository.rb
local_pac-0.1.1 lib/local_pac/git_repository.rb
local_pac-0.1.0 lib/local_pac/git_repository.rb