Sha256: 3cc354ee2f0b17ec603a7de61b4eac78d62c614cad4529514d0a39670b049092

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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
      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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
local_pac-0.1.10 lib/local_pac/git_repository.rb