Class: Ruby::Nginx::System::SafeFile

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/nginx/system/safe_file.rb

Class Method Summary collapse

Class Method Details

.exist?(file_path) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/ruby/nginx/system/safe_file.rb', line 18

def exist?(file_path)
  File.exist?(File.expand_path(file_path))
end

.mkdir(dir_path) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/ruby/nginx/system/safe_file.rb', line 10

def mkdir(dir_path)
  safe_path = File.expand_path(dir_path)

  FileUtils.mkdir_p(safe_path)

  safe_path
end

.read(file_path) ⇒ Object



31
32
33
# File 'lib/ruby/nginx/system/safe_file.rb', line 31

def read(file_path)
  File.read(File.expand_path(file_path))
end

.rm(file_path) ⇒ Object



43
44
45
# File 'lib/ruby/nginx/system/safe_file.rb', line 43

def rm(file_path)
  FileUtils.rm_f(File.expand_path(file_path))
end

.touch(file_path) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/ruby/nginx/system/safe_file.rb', line 22

def touch(file_path)
  safe_path = File.expand_path(file_path)

  FileUtils.mkdir_p(File.dirname(safe_path))
  FileUtils.touch(safe_path)

  safe_path
end

.write(file_path, content) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/ruby/nginx/system/safe_file.rb', line 35

def write(file_path, content)
  safe_path = touch(file_path)

  File.write(safe_path, content)

  safe_path
end