module Comodule::Deployment::Helper::SystemUtility
Public Instance Methods
be_dir(*dir)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 57 def be_dir(*dir) dir = dir.flatten if dir.size > 1 return dir.map { |d| be_dir(d) } end dir = dir[0] FileUtils.mkdir_p dir unless File.directory?(dir) dir end
be_file(*path)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 69 def be_file(*path) path = path.flatten if path.size > 1 return path.map { |p| be_file(p) } end path = path[0] FileUtils.touch path if !File.directory?(path) && !File.file?(path) path end
re_dir(*dir)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 44 def re_dir(*dir) dir = dir.flatten if dir.size > 1 return dir.map { |d| re_dir(d) } end dir = dir[0] rm_rf dir be_dir(dir) end
render(path)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 3 def render(path) ERB.new(File.read(path)).result(binding) end
render_in_dir(file_path, in_dir)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 19 def render_in_dir(file_path, in_dir) dir, filename = File.split(file_path) path_in_dir = File.join(in_dir, filename.sub(/\.erb$/, '')) render_in_path file_path, path_in_dir end
render_in_path(from, to)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 7 def render_in_path(from, to) File.open(to, 'w') do |file| if from =~ /\.erb$/ file.write render(from) else file.write File.read(from) end end to end
rm_rf(dir)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 33 def rm_rf(dir) unless dir.to_s =~ %r|^#{platform_root}| raise ArgumentError, "#{self.class.name}##{__method__} cannot remove outside of #platform_root" end return unless File.directory?(dir) `rm -rf #{dir}` dir end
yaml_to_config(path)
click to toggle source
# File lib/comodule/deployment/helper/system_utility.rb, line 27 def yaml_to_config(path) ::Comodule::ConfigSupport::Config.new( YAML.load_file( path ) || {} ) end