Module: SafeFile

Defined in:
lib/safefile.rb

Constant Summary collapse

@@safeDirs =
Array.new
@@allowPWD =
true

Instance Method Summary collapse

Instance Method Details

#allowPWDObject



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

def allowPWD
  return @@allowPWD
end

#allowPWD=(bool) ⇒ Object



54
55
56
# File 'lib/safefile.rb', line 54

def allowPWD= bool
  @@allowPWD = bool
end

#append(dir) ⇒ Object



42
43
44
45
46
# File 'lib/safefile.rb', line 42

def append dir 
  dir = dir.gsub "~/", "#{ENV["HOME"]}/"

  @@safeDirs.append dir
end

#foreach(file, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/safefile.rb', line 31

def foreach file, &block
  file = file.gsub "~/", "#{ENV["HOME"]}/"

  if performCheck File.expand_path file
    File.foreach file do |line|
      block.call line
    end
  end   
end

#open(file) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/safefile.rb', line 7

def open file
  file = file.gsub "~/", "#{ENV["HOME"]}/"

  if performCheck File.expand_path file
    return File.open file
  end
end

#read(file) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/safefile.rb', line 15

def read file
  file = file.gsub "~/", "#{ENV["HOME"]}/"

  if performCheck File.expand_path file
    return File.read file
  end
end

#remove(dir) ⇒ Object



48
49
50
51
52
# File 'lib/safefile.rb', line 48

def remove dir 
  dir = dir.gsub "~/", "#{ENV["HOME"]}/"

  @@safeDirs.delete dir
end

#safeObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/safefile.rb', line 41

def safe 
  def append dir 
    dir = dir.gsub "~/", "#{ENV["HOME"]}/"

    @@safeDirs.append dir
  end

  def remove dir 
    dir = dir.gsub "~/", "#{ENV["HOME"]}/"

    @@safeDirs.delete dir
  end

  def allowPWD= bool
    @@allowPWD = bool
  end 

  def allowPWD
    return @@allowPWD
  end

  return @@safeDirs
end

#write(file, content) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/safefile.rb', line 23

def write file, content
  file = file.gsub "~/", "#{ENV["HOME"]}/"

  if performCheck File.expand_path file
    File.write file, content
  end
end