Class: Helpers::NewFile

Inherits:
Object
  • Object
show all
Defined in:
lib/amnesie/helpers.rb

Direct Known Subclasses

NewSystemd

Instance Method Summary collapse

Constructor Details

#initialize(string, name, dest = "/tmp") ⇒ NewFile

Returns a new instance of NewFile.



23
24
25
26
27
# File 'lib/amnesie/helpers.rb', line 23

def initialize(string, name, dest = "/tmp")
  @string = string
  @name = name
  @dest = dest + "/" + @name
end

Instance Method Details

#addObject



29
30
31
32
33
34
35
36
# File 'lib/amnesie/helpers.rb', line 29

def add
  @mv = Helpers::Exec.new("mv")
  tmp = Tempfile.new(@name)
  File.open(tmp.path, 'w') do |file|
    file.puts @string
  end
  @mv.run("#{tmp.path} #{@dest}")
end

#perm(user, perm) ⇒ Object



38
39
40
41
42
43
# File 'lib/amnesie/helpers.rb', line 38

def perm(user, perm)
  chown = Helpers::Exec.new("chown")
  chmod = Helpers::Exec.new("chmod")
  chown.run("#{user}:#{user} #{@dest}")
  chmod.run("#{perm} #{@dest}")
end