class Bosh::Gen::Generators::ErrandGenerator

Public Class Methods

source_root() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 12
def self.source_root
  File.join(File.dirname(__FILE__), "errand_generator", "templates")
end

Public Instance Methods

check_name() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 22
def check_name
  raise Thor::Error.new("'#{job_name}' is not a valid BOSH id") unless job_name.bosh_valid_id?
end
check_root_is_release() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 16
def check_root_is_release
  unless File.exist?("jobs") && File.exist?("packages")
    raise Thor::Error.new("run inside a BOSH release project")
  end
end
job_specification() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 56
def job_specification
  config = { "name" => job_name, "packages" => dependencies, "templates" => @template_files }
  create_file job_dir("spec"), YAML.dump(config)
end
readme() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 61
def readme
  say_status "readme", "Add job to deploymemt manifest with lifecycle: errand"
end
template_files() click to toggle source

copy the thor template files into the bosh release to be bosh templates that's right, templates (.tt) can become templates (.erb)

# File lib/bosh/gen/generators/errand_generator.rb, line 37
def template_files
  generator_job_templates_path = File.join(self.class.source_root, "jobs/%job_name%")
  directory "jobs/%job_name%", "jobs/#{job_name}"

  # build a hash of { 'bin/webapp_ctl.erb' => 'bin/webapp_ctl', ...} used in spec
  @template_files = {}
  FileUtils.chdir(File.join(generator_job_templates_path, "templates")) do
    %x`ls */*`.split("\n").each do |template_file|
      # clean up thor name convention
      template_file.gsub!("%job_name%", job_name)
      template_file.gsub!(".tt", "")
      # strip erb from target file
      target_template_file = template_file.gsub(/.erb/, '')

      @template_files[template_file] = target_template_file
    end
  end
end
warn_missing_dependencies() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 26
def warn_missing_dependencies
  dependencies.each do |d|
    raise Thor::Error.new("dependency '#{d}' is not a valid BOSH id") unless d.bosh_valid_id?
    unless File.exist?(File.join("packages", d))
      say_status "warning", "missing dependency '#{d}'", :yellow
    end
  end
end

Private Instance Methods

filenames() click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 66
def filenames
  files.map {|f| File.basename(f) }
end
git(commands={}) click to toggle source

Run a command in git.

Examples

git :init
git :add => "this.file that.rb"
git :add => "onefile.rb", :rm => "badfile.cxx"
# File lib/bosh/gen/generators/errand_generator.rb, line 82
def git(commands={})
  if commands.is_a?(Symbol)
    run "git #{commands}"
  else
    commands.each do |cmd, options|
      run "git #{cmd} #{options}"
    end
  end
end
job_dir(path) click to toggle source
# File lib/bosh/gen/generators/errand_generator.rb, line 70
def job_dir(path)
  File.join("jobs", job_name, path)
end