Class: Dir

Inherits:
Object
  • Object
show all
Defined in:
lib/vcpkg_pipeline/extension/dir_vpl.rb

Overview

Dir

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.replace_all(path, replacements) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vcpkg_pipeline/extension/dir_vpl.rb', line 20

def self.replace_all(path, replacements)
  Dir["#{path}/*"].each do |subpath|
    subpath_rpl = subpath
    replacements.each { |find, replace| subpath_rpl = subpath_rpl.gsub(find, replace)}
    File.rename(subpath, subpath_rpl)

    if File.directory? subpath_rpl
      replace_all(subpath_rpl, replacements)
    else
      replace_content(subpath_rpl, replacements)
    end
  end
end

.replace_content(path, replacements) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/vcpkg_pipeline/extension/dir_vpl.rb', line 12

def self.replace_content(path, replacements)
  content = File.read(path)
  replacements.each do |find, replace|
    content = content.gsub(find, replace)
  end
  File.write(path, content)
end

Instance Method Details

#reset(path) ⇒ Object



5
6
7
8
9
10
# File 'lib/vcpkg_pipeline/extension/dir_vpl.rb', line 5

def reset(path)
  return unless File.directory? path

  `rm -fr #{path}`
  `mkdir #{path}`
end