class Helpers::NewFile

Class Newfile Create a file and move at the dest

Example

string = “nameserver 127.0.0.1” name = “resolv.conf” dest = “/etc” new_file = Helpers::Newfile.new(string, name, dest) new_file.add

Public Class Methods

new(string, name, dest = "/tmp") click to toggle source

Method new

Parameters

  • string = string for the whole file

  • name = name of the file (e.g: resolv.conf)

  • dest = path (e.g: /etc)

# File lib/spior/helpers.rb, line 41
def initialize(string, name, dest = "/tmp")
  @string = string
  @name = name
  @dest = dest + "/" + @name
end

Public Instance Methods

add() click to toggle source

Method add Add the file at @dest

# File lib/spior/helpers.rb, line 49
def add
  @mv = Helpers::Exec.new("mv")
  tmp = Tempfile.new(@name)
  File.open(tmp.path, 'w') do |file|
    file.puts @string
  end
  puts "move #{tmp.path} to #{@dest}"
  @mv.run("#{tmp.path} #{@dest}")
end
perm(user, perm) click to toggle source
# File lib/spior/helpers.rb, line 59
def perm(user, perm)
  chown = Helpers::Exec.new("chown")
  chmod = Helpers::Exec.new("chmod")
  chown.run("#{user}:#{user} #{@dest}")
  chmod.run("#{perm} #{@dest}")
end