Module: Tenter::Utils Private

Defined in:
lib/tenter/utils.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Utility functions for use by Tenter

Since:

  • 0.1.1

Class Method Summary collapse

Class Method Details

.append_to_log(log, statement) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Appends a statement to the log

Parameters:

  • log (String)

    the file representing the log

  • statement (String)

    the statement to append to the log

Since:

  • 0.1.0



94
95
96
# File 'lib/tenter/utils.rb', line 94

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

.command(command_name, site_dir) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The directory provided must be given relative to the document root.

Returns the details of the command to execute

Parameters:

  • command_name (String)

    the name of the file representing the command

  • site_dir (String)

    the directory containing the command

Returns:

  • (Hash)

    the details of the command to execute

Since:

  • 0.1.1



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/tenter/utils.rb', line 64

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The basename of the YAML file is specified in Tenter’s configuration

Loads configuration data from a YAML file for a given directory

settings.

Parameters:

  • site_dir (String)

    the directory containing the YAML file

Since:

  • 0.1.1



22
23
24
25
26
27
28
# File 'lib/tenter/utils.rb', line 22

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

The directory provided must be given relative to the document root.

Checks if the directory exists

Parameters:

  • site_dir (String)

    the directory to check

Returns:

  • (Boolean)

Since:

  • 0.1.1



38
39
40
# File 'lib/tenter/utils.rb', line 38

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

.secret(site_dir) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the secret value for a particular directory

Parameters:

  • site_dir (String)

    the directory

Since:

  • 0.1.1



48
49
50
# File 'lib/tenter/utils.rb', line 48

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