Class: PleaseRun::Platform::Base

Inherits:
Object
  • Object
show all
Includes:
Configurable, MustacheMethods
Defined in:
lib/pleaserun/platform/base.rb

Overview

Base class for all platforms.

This class provides all the general attributes common among all process runners.

For example, pretty much every runner (upstart, runit, sysv, etc) has concepts for the ‘name’ of a thing, what program it runs, what user to run as, etc.

Direct Known Subclasses

Launchd, Runit, SYSV, Systemd, SystemdUser, Upstart

Defined Under Namespace

Classes: InvalidTemplate

Instance Method Summary collapse

Methods included from MustacheMethods

#escaped, #escaped_args, #quoted, #shell_args, #shell_continuation, #shell_quote

Methods included from Configurable

#configurable_setup, included, #validate

Constructor Details

#initialize(target_version) ⇒ Base

Returns a new instance of Base.



140
141
142
143
# File 'lib/pleaserun/platform/base.rb', line 140

def initialize(target_version)
  configurable_setup
  self.target_version = target_version
end

Instance Method Details

#install_actionsObject

The default install_actions is none.

Subclasses which need installation actions should implement this method. This method will return an Array of String commands to execute in order to install this given runner.

For examples, see launchd and systemd platforms.



190
191
192
# File 'lib/pleaserun/platform/base.rb', line 190

def install_actions
  return []
end

#platformObject

Get the platform name for this class. The platform name is simply the lowercased class name, but this can be overridden by subclasses (but don’t, because that makes things confusing!)



147
148
149
# File 'lib/pleaserun/platform/base.rb', line 147

def platform
  self.class.name.split("::").last.gsub(/(?<=[^A-Z])[A-Z]+/, "-\\0").downcase
end

#render(text) ⇒ Object

Render a text input through Mustache based on this object.



172
173
174
# File 'lib/pleaserun/platform/base.rb', line 172

def render(text)
  return Mustache.render(text, self)
end

#render_template(name) ⇒ Object

def template_path

Raises:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/pleaserun/platform/base.rb', line 156

def render_template(name)
  possibilities = [ 
    File.join(template_path, target_version, name),
    File.join(template_path, "default", name),
    File.join(template_path, name)
  ]

  possibilities.each do |path|
    next unless File.readable?(path) && File.file?(path)
    return render(File.read(path))
  end

  raise InvalidTemplate, "Could not find template file for '#{name}'. Tried all of these: #{possibilities.inspect}"
end

#safe_filename(str) ⇒ Object

Get a safe-ish filename.

This renders ‘str` through Mustache and replaces spaces with underscores.



179
180
181
# File 'lib/pleaserun/platform/base.rb', line 179

def safe_filename(str)
  return render(str).gsub(" ", "_")
end

#sysv_logObject

def install_actions



194
195
196
197
198
199
200
# File 'lib/pleaserun/platform/base.rb', line 194

def sysv_log
  if sysv_log_directory?
    File.join(sysv_log_path, name)
  else
    sysv_log_path
  end
end

#sysv_log_directory?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/pleaserun/platform/base.rb', line 202

def sysv_log_directory?
  return sysv_log_path.end_with?("/")
end

#template_pathObject

Get the template path for this platform.



152
153
154
# File 'lib/pleaserun/platform/base.rb', line 152

def template_path
  return File.join(File.dirname(__FILE__), "../../../templates", platform)
end