Class: LocalPac::GitStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/local_pac/git_storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(storage_path, compressor_engine = JavaScriptCompressor, vcs_engine = GitRepository, null_file = LocalPac::NullFile.new) ⇒ GitStorage



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/local_pac/git_storage.rb', line 11

def initialize(storage_path, compressor_engine = JavaScriptCompressor, vcs_engine = GitRepository, null_file = LocalPac::NullFile.new)
  @storage_path = ::File.expand_path(storage_path)
  @null_file    = null_file
  @vcs_engine   = vcs_engine
  @compressor_engine = compressor_engine

  begin
    @repository = vcs_engine.new(storage_path)
  rescue Exceptions::RepositoryDoesNotExist
    @repository = vcs_engine.create(storage_path)
  end

  LocalPac.ui_logger.debug 'Available pac files by path: ' + pac_files.collect {|p| "\"#{p.path}\"" }.join(", ")
  LocalPac.ui_logger.debug 'Available pac files by name: ' + pac_files.collect {|p| "\"#{p.name}\"" }.join(", ")

  @data = load_data

  LocalPac.ui_logger.debug 'Loaded pac files by path: ' + @data.collect {|_,p| "\"#{p.path}\"" }.join(", ")
  LocalPac.ui_logger.debug 'Loaded pac files by name: ' + @data.collect {|_,p| "\"#{p.name}\"" }.join(", ")
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
# File 'lib/local_pac/git_storage.rb', line 32

def [](key)
  data.fetch(key, null_file)
end

#each_added_pac_file(old_commit_id, new_commit_id, &block) ⇒ Object



40
41
42
# File 'lib/local_pac/git_storage.rb', line 40

def each_added_pac_file(old_commit_id, new_commit_id, &block)
  added_pac_files(old_commit_id, new_commit_id).each(&block)
end

#each_pac_file(&block) ⇒ Object



36
37
38
# File 'lib/local_pac/git_storage.rb', line 36

def each_pac_file(&block)
  pac_files.each(&block)
end