Class: CarthageCacheRes::Archiver

Inherits:
Object
  • Object
show all
Defined in:
lib/carthage_cache_res/archiver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(executor = ShellCommandExecutor.new) ⇒ Archiver

Returns a new instance of Archiver.



7
8
9
# File 'lib/carthage_cache_res/archiver.rb', line 7

def initialize(executor = ShellCommandExecutor.new)
  @executor = executor
end

Instance Attribute Details

#executorObject (readonly)

Returns the value of attribute executor.



5
6
7
# File 'lib/carthage_cache_res/archiver.rb', line 5

def executor
  @executor
end

Instance Method Details

#archive(archive_path, destination_path, &filter_block) ⇒ Object



11
12
13
14
15
16
# File 'lib/carthage_cache_res/archiver.rb', line 11

def archive(archive_path, destination_path, &filter_block)
  files = Dir.entries(archive_path).select { |x| !x.start_with?(".") }
  files = files.select(&filter_block) if filter_block
  files = files.sort_by(&:downcase)
  executor.execute("cd #{archive_path} && zip -r -X #{File.expand_path(destination_path)} #{files.join(' ')} > /dev/null")
end

#unarchive(archive_path, destination_path) ⇒ Object



18
19
20
# File 'lib/carthage_cache_res/archiver.rb', line 18

def unarchive(archive_path, destination_path)
  executor.execute("unzip -o #{archive_path} -d #{destination_path} > /dev/null")
end