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
Class Method Summary collapse
-
.append_to_log(log, statement) ⇒ Object
private
Appends a statement to the log.
-
.command(command_name, site_dir) ⇒ Hash
private
Returns the details of the command to execute.
-
.config(site_dir) ⇒ Object
private
Loads configuration data from a YAML file for a given directory.
-
.dir_exists?(site_dir) ⇒ Boolean
private
Checks if the directory exists.
-
.secret(site_dir) ⇒ Object
private
Returns the secret value for a particular directory.
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
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.
The directory provided must be given relative to the document root.
Returns the details of the command to execute
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.
The basename of the YAML file is specified in Tenter’s configuration
Loads configuration data from a YAML file for a given directory
settings.
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.
The directory provided must be given relative to the document root.
Checks if the directory exists
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
48 49 50 |
# File 'lib/tenter/utils.rb', line 48 def self.secret(site_dir) self.config(site_dir).fetch("secret", nil) end |