Module: Comodule::Deployment::Helper::SystemUtility
- Defined in:
- lib/comodule/deployment/helper/system_utility.rb
Instance Method Summary collapse
- #be_dir(*dir) ⇒ Object
- #be_file(*path) ⇒ Object
- #re_dir(*dir) ⇒ Object
- #render(path) ⇒ Object
- #render_in_dir(file_path, in_dir) ⇒ Object
- #render_in_path(from, to) ⇒ Object
- #rm_rf(dir) ⇒ Object
- #yaml_to_config(path) ⇒ Object
Instance Method Details
#be_dir(*dir) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# 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) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# 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) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# 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) ⇒ Object
3 4 5 |
# 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) ⇒ Object
19 20 21 22 23 24 25 |
# 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) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# 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) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# 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) ⇒ Object
27 28 29 30 31 |
# File 'lib/comodule/deployment/helper/system_utility.rb', line 27 def yaml_to_config(path) ::Comodule::ConfigSupport::Config.new( YAML.load_file( path ) || {} ) end |