class Sambot::Chef::Generator

Public Class Methods

from_templates(config, cloud, local_workflow, generated_files) click to toggle source
# File lib/sambot/chef/generator.rb, line 9
def self.from_templates(config, cloud, local_workflow, generated_files)
  generated_files.each { |template_name, opts| generate_from_template(template_name.to_s, opts, config) }
  generate_bootstrap_scripts(config, cloud, local_workflow)
end

Private Class Methods

bootstrap(config, path) click to toggle source
# File lib/sambot/chef/generator.rb, line 24
def self.bootstrap(config, path)
  bootstrap_centos(path) if config.runs_on_centos?
  bootstrap_windows(path) if config.runs_on_windows?
end
bootstrap_centos(path) click to toggle source
# File lib/sambot/chef/generator.rb, line 16
def self.bootstrap_centos(path)
  generate_bootstrap_from_template(path, 'sh')
end
bootstrap_windows(path) click to toggle source
# File lib/sambot/chef/generator.rb, line 20
def self.bootstrap_windows(path)
  generate_bootstrap_from_template(path, 'ps1')
end
exists!(path) click to toggle source
# File lib/sambot/chef/generator.rb, line 37
def self.exists!(path)
  return if File.exist?(path) || Dir.exist?(path)
  raise ApplicationError, "The file or directory #{path} was not found in the current directory."
end
generate_bootstrap_from_template(path, suffix) click to toggle source
# File lib/sambot/chef/generator.rb, line 29
def self.generate_bootstrap_from_template(path, suffix)
  Template.new("bootstrap_scripts/#{path}/bootstrap.#{suffix}.erb").process(eruby: true, dest: "bootstrap.#{suffix}")
end
generate_bootstrap_scripts(config, cloud, local_workflow) click to toggle source
# File lib/sambot/chef/generator.rb, line 33
def self.generate_bootstrap_scripts(config, cloud, local_workflow)
  cloud != 'local' ? bootstrap(config, cloud) : bootstrap(config, "local/#{local_workflow}")
end
generate_from_template(template_file, opts, config) click to toggle source
# File lib/sambot/chef/generator.rb, line 42
def self.generate_from_template(template_file, opts, config)
  UI.debug("Processing #{template_file} with opts #{opts.inspect} on platform #{config.available_platforms}")
  template = Template.new(template_file)
  if valid_platform?(opts, config)
    template.process(opts)
    UI.debug("#{opts[:dest]} has been added to the cookbook.")
  end
end
valid_platform?(opts, config) click to toggle source
# File lib/sambot/chef/generator.rb, line 51
def self.valid_platform?(opts, config)
  targets = opts[:platform].map(&:to_s)
  result = targets & config.available_platforms
  result.size.positive?
end