class Object

Public Instance Methods

check_procfile!() click to toggle source
# File lib/foreman/cli.rb, line 133
def check_procfile!
  error("#{procfile} does not exist.") unless File.file?(procfile)
end
chmod(mode, file) click to toggle source
# File lib/foreman/export/base.rb, line 146
def chmod(mode, file)
  say "setting #{file} to mode #{mode}"
  FileUtils.chmod mode, File.join(location, file)
end
chown(user, dir) click to toggle source
# File lib/foreman/export/base.rb, line 83
def chown user, dir
  FileUtils.chown user, nil, dir
rescue
  error("Could not chown #{dir} to #{user}") unless File.writable?(dir) || ! File.exists?(dir)
end
clean(filename) click to toggle source
# File lib/foreman/export/base.rb, line 97
def clean(filename)
  return unless File.exists?(filename)
  say "cleaning up: #{filename}"
  FileUtils.rm(filename)
end
clean_dir(dirname) click to toggle source
# File lib/foreman/export/base.rb, line 103
def clean_dir(dirname)
  return unless File.exists?(dirname)
  say "cleaning up directory: #{dirname}"
  FileUtils.rm_r(dirname)
end
create_directory(dir) click to toggle source
# File lib/foreman/export/base.rb, line 151
def create_directory(dir)
  say "creating: #{dir}"
  FileUtils.mkdir_p(File.join(location, dir))
end
error(message) click to toggle source
# File lib/foreman/export/base.rb, line 89
def error(message)
  raise Foreman::Export::Exception.new(message)
end
export_template(name, file=nil, template_root=nil) click to toggle source
# File lib/foreman/export/base.rb, line 124
def export_template(name, file=nil, template_root=nil)
  if file && template_root
    old_export_template name, file, template_root
  else
    name_without_first = name.split("/")[1..-1].join("/")
    matchers = []
    matchers << File.join(options[:template], name_without_first) if options[:template]
    matchers << File.expand_path("~/.foreman/templates/#{name}")
    matchers << File.expand_path("../../../../data/export/#{name}", __FILE__)
    File.read(matchers.detect { |m| File.exists?(m) })
  end
end
load_environment!() click to toggle source
# File lib/foreman/cli.rb, line 137
def load_environment!
  if options[:env]
    options[:env].split(",").each do |file|
      engine.load_env file
    end
  else
    default_env = File.join(engine.root, ".env")
    engine.load_env default_env if File.file?(default_env)
  end
end
old_export_template(exporter, file, template_root) click to toggle source

deprecated

# File lib/foreman/export/base.rb, line 114
def old_export_template(exporter, file, template_root)
  if template_root && File.exist?(file_path = File.join(template_root, file))
    File.read(file_path)
  elsif File.exist?(file_path = File.expand_path(File.join("~/.foreman/templates", file)))
    File.read(file_path)
  else
    File.read(File.expand_path("../../../../data/export/#{exporter}/#{file}", __FILE__))
  end
end
options() click to toggle source
Calls superclass method
# File lib/foreman/cli.rb, line 156
def options
  original_options = super
  return original_options unless File.file?(".foreman")
  defaults = ::YAML::load_file(".foreman") || {}
  Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
end
procfile() click to toggle source
# File lib/foreman/cli.rb, line 148
def procfile
  case
    when options[:procfile] then options[:procfile]
    when options[:root]     then File.expand_path(File.join(options[:root], "Procfile"))
    else "Procfile"
  end
end
say(message) click to toggle source
# File lib/foreman/export/base.rb, line 93
def say(message)
  puts "[foreman export] %s" % message
end
shell_quote(value) click to toggle source
# File lib/foreman/export/base.rb, line 109
def shell_quote(value)
  Shellwords.escape(value)
end
write_file(filename, contents) click to toggle source
# File lib/foreman/export/base.rb, line 161
def write_file(filename, contents)
  say "writing: #{filename}"

  filename = File.join(location, filename) unless Pathname.new(filename).absolute?

  File.open(filename, "w") do |file|
    file.puts contents
  end
end
write_template(name, target, binding) click to toggle source
# File lib/foreman/export/base.rb, line 137
def write_template(name, target, binding)
  compiled = if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
               ERB.new(export_template(name), trim_mode: '-').result(binding)
             else
               ERB.new(export_template(name), nil, '-').result(binding)
             end
  write_file target, compiled
end