Class: LocalPac::Actions::AddExamplesToLocalStorage

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

Instance Method Summary collapse

Constructor Details

#initialize(storage_path, options = {}, vcs_engine = GitRepository) ⇒ AddExamplesToLocalStorage

Returns a new instance of AddExamplesToLocalStorage.



12
13
14
15
16
# File 'lib/local_pac/actions/add_examples_to_local_storage.rb', line 12

def initialize(storage_path, options = {}, vcs_engine = GitRepository)
  @options      = options
  @vcs_engine   = vcs_engine
  @storage_path = storage_path
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/local_pac/actions/add_examples_to_local_storage.rb', line 18

def run
  @files        = Dir.glob(::File.expand_path('../../../../files/examples/*', __FILE__)).collect do |f| 
    OpenStruct.new(repo_path: "examples/#{::File.basename(f)}", name: "examples::#{::File.basename(f).sub(/\.[^.]+$/, '')}".to_sym, content: ::File.read(f))
  end
  @files << OpenStruct.new(repo_path: 'proxy.pac', name: :proxy, content: ::File.read(::File.expand_path('../../../../files/proxy.pac', __FILE__)))

  begin
    @repo = vcs_engine.new(storage_path)
  rescue Rugged::OSError
    raise Exceptions::RepositoryDoesNotExist, "Sorry, but the repository at #{storage_path} does not exist" unless ::Dir.exists? storage_path
  end

  if need_to_run? || options[:force] == true
    files.each { |f| repo.add_content(f.repo_path, f.content) }
    repo.add_content('proxy.pac', ::File.read(::File.expand_path('../../../../files/proxy.pac', __FILE__)))
  else
    LocalPac.ui_logger.warn "Example files already exists. Do not create them again!."
  end
end