Class: Edploy::FileHandling

Inherits:
Object
  • Object
show all
Defined in:
lib/edployscripts/file_handling.rb

Class Method Summary collapse

Class Method Details

.iterate_dir_items(base_dir, &block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/edployscripts/file_handling.rb', line 16

def iterate_dir_items(base_dir, &block)
  Dir["#{base_dir}/**"].each do |fqpn|
    entry = fqpn.sub(/^#{base_dir}\//, '')
    dirname = File.dirname(entry)
    filename = File.basename(entry)
    yield(dirname, filename, relative_entry, fqpn)
  end
end

.upload_file(file, tmp_path, &block) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/edployscripts/file_handling.rb', line 6

def upload_file(file, tmp_path, &block)
  if File.exists?(file)
    random_string = "#{Time.now.to_i}"
    tmp_file = "#{tmp_path}/#{random_string}-#{File.basename(file)}"
    commands << "mkdir -p #{File.dirname(tmp_file)}"
    put File.read(file), tmp_file, :mode => 0644
    yield(tmp_file)
  end
end