Module: Superhosting::Helper::File

Included in:
Superhosting::Helpers
Defined in:
lib/superhosting/helper/file.rb

Instance Method Summary collapse

Instance Method Details

#chmod!(mode, path) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/superhosting/helper/file.rb', line 46

def chmod!(mode, path)
  self.debug_operation(desc: { code: :chmod, data: { mode: mode, path: path } }) do |&blk|
    self.with_dry_run do |dry_run|
      FileUtils.chmod(mode, path) unless dry_run
      blk.call(code: :ok)
    end
  end
end

#chown!(user, group, path) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/superhosting/helper/file.rb', line 37

def chown!(user, group, path)
  self.debug_operation(desc: { code: :chown, data: { user: user, group: group, path: path } }) do |&blk|
    self.with_dry_run do |dry_run|
      FileUtils.chown(user, group, path) unless dry_run
      blk.call(code: :ok)
    end
  end
end

#chown_r!(user, group, path) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/superhosting/helper/file.rb', line 28

def chown_r!(user, group, path)
  self.debug_operation(desc: { code: :chown_r, data: { user: user, group: group, path: path } }) do |&blk|
    self.with_dry_run do |dry_run|
      FileUtils.chown_R(user, group, path) unless dry_run
      blk.call(code: :ok)
    end
  end
end

#safe_link!(path_to, path) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/superhosting/helper/file.rb', line 4

def safe_link!(path_to, path)
  self.debug_operation(desc: { code: :symlink, data: { path_to: path_to, path: path } }) do |&blk|
    if ::File.exist? path
      blk.call(code: :ok)
    else
      self.with_dry_run do |dry_run|
        ::File.symlink(path_to, path) unless dry_run
        blk.call(code: :created)
      end
    end
  end
end

#safe_unlink!(path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/superhosting/helper/file.rb', line 17

def safe_unlink!(path)
  if ::File.exist? path
    self.debug_operation(desc: { code: :symlink, data: { path: path } }) do |&blk|
      self.with_dry_run do |dry_run|
        ::File.unlink(path) unless dry_run
        blk.call(code: :deleted)
      end
    end
  end
end