Module: Crafti::FileUtilsExtension

Included in:
Root
Defined in:
lib/crafti.rb

Instance Method Summary collapse

Instance Method Details

#chmod(mode, file) ⇒ Object



58
59
60
61
# File 'lib/crafti.rb', line 58

def chmod(mode, file)
  file = [file].flatten.map { |f| app_path.join(f).to_s }
  ::FileUtils.chmod(mode, file)
end

#chmod_r(mode, file) ⇒ Object



63
64
65
66
# File 'lib/crafti.rb', line 63

def chmod_r(mode, file)
  file = [file].flatten.map { |f| app_path.join(f).to_s }
  ::FileUtils.chmod_R(mode, file)
end

#copy(list, dir, options = {}) ⇒ Object Also known as: cp



53
54
55
# File 'lib/crafti.rb', line 53

def copy(list, dir, options = {})
  ::FileUtils.cp(list, app_path.join(dir).to_s, options)
end

#mkdir(dir, options = {}) ⇒ Object Also known as: mkdir_p



36
37
38
# File 'lib/crafti.rb', line 36

def mkdir(dir, options = {})
  ::FileUtils.mkdir_p(app_path.join(dir).to_s, options)
end

#mkdirs(*directories, mode: 0644, noop: false) ⇒ Object



41
42
43
44
45
# File 'lib/crafti.rb', line 41

def mkdirs(*directories, mode: 0644, noop: false)
  directories.each do |dir|
    mkdir(dir, mode: mode, verbose: false, noop: noop)
  end
end

#run(command) ⇒ Object



68
69
70
# File 'lib/crafti.rb', line 68

def run(command)
  system("cd #{app_path} && #{command}")
end

#sudo(command) ⇒ Object



72
73
74
# File 'lib/crafti.rb', line 72

def sudo(command)
  run "sudo #{command}"
end

#template(dest, erb_template, values) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/crafti.rb', line 76

def template(dest, erb_template, values)
  temp = ::Pathname.new(erb_template)

  namespace = TemplateBinding.new(values)
  content   = ::ERB.new(temp.read).
    result(namespace.get_binding)

  ::File.open(app_path.join(dest).to_s, 'w+') do |f|
    f.puts content
  end
end

#touch(*files, noop: false) ⇒ Object



47
48
49
50
51
# File 'lib/crafti.rb', line 47

def touch(*files, noop: false)
  files.each do |file|
    ::FileUtils.touch(app_path.join(file).to_s, verbose: false, noop: noop)
  end
end