Class: PleaseRun::User::Base

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

Constant Summary collapse

InvalidTemplate =
Class.new(StandardError)
STRING =
proc do
  validate do |v|
    insist { v }.is_a?(String)
  end
end
STRING_OR_NIL =
proc do
  validate do |v|
    begin
      insist { v }.is_a?(String)
    rescue Insist::Failure
      begin
        insist { v }.nil?
      rescue Insist::Failure
        raise Insist::Failure, "Expected #{v} to be a String or nil value."
      end
    end
  end
end

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

Instance Method Details

#render(text) ⇒ Object

Render a text input through Mustache based on this object.



64
65
66
# File 'lib/pleaserun/user/base.rb', line 64

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

#render_installerObject



35
36
37
# File 'lib/pleaserun/user/base.rb', line 35

def render_installer
  render_template("installer.sh")
end

#render_removerObject



39
40
41
# File 'lib/pleaserun/user/base.rb', line 39

def render_remover
  render_template("remover.sh")
end

#render_template(name) ⇒ Object

def template_path

Raises:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pleaserun/user/base.rb', line 48

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

  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

#template_pathObject

Get the template path for this platform.



44
45
46
# File 'lib/pleaserun/user/base.rb', line 44

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