Module: Tenter::Utils

Defined in:
lib/tenter/utils.rb

Class Method Summary collapse

Class Method Details

.append_to_log(log, statement) ⇒ Object



46
47
48
# File 'lib/tenter/utils.rb', line 46

def self.append_to_log(log, statement)
  File.write(log, statement, mode: "a")
end

.command(command_name, site_dir) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/tenter/utils.rb', line 23

def self.command(command_name, site_dir)
  site_path = File.join(Tenter.settings[:doc_root], site_dir)
  command = {}
  command["dir"]  = File.join(site_path, Tenter.settings[:command_dir])
  command["path"] = File.join(command["dir"], command_name)
  command["log"]  = unless Tenter.settings[:log_file].nil?
                      File.join(site_path, Tenter.settings[:log_file])
                    else
                      "/dev/null"
                    end
  command["proc"] = Proc.new {
    ts = if Tenter.settings[:timestamp]
           %q{ | xargs -L 1 sh -c 'printf "[%s] %s\n" "$(date +%Y-%m-%d\ %H:%M:%S\ %z )" "$*" ' sh}
         else
           ""
         end
    spawn command["path"] + ts, { :chdir => command["dir"],
                                  [ :out, :err ] => [ command["log"], "a" ] }
  }

  return command
end

.config(site_dir) ⇒ Object



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

def self.config(site_dir)
  @config ||= {}
  @config[site_dir] ||=
    YAML.load_file(File.join(Tenter.settings[:doc_root],
                   site_dir,
                   Tenter.settings[:config_filename]))
end

.dir_exists?(site_dir) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/tenter/utils.rb', line 15

def self.dir_exists?(site_dir)
  File.directory? File.join(Tenter.settings[:doc_root], site_dir)
end

.secret(site_dir) ⇒ Object



19
20
21
# File 'lib/tenter/utils.rb', line 19

def self.secret(site_dir)
  self.config(site_dir).fetch("secret", nil)
end