Sha256: cca97df506cf8a95bcadc3e7102b4323e2079c0ab3d3c495fbfd6e3cdc42cacc
Contents?: true
Size: 1.62 KB
Versions: 9
Compression:
Stored size: 1.62 KB
Contents
require "fileutils" require "rubygems" require "bundler/setup" module Conan class Initializer TEMPLATE_PATH = File.expand_path("../template", __FILE__) ShellCommandError = Class.new(RuntimeError) def self.run(where, settings) new(where, settings).run end def initialize(where, settings) @destination = File.expand_path(where) @settings = Conan::Settings.new(settings) end def run copy_template add_gitignore add_git_submodule end private def add_gitignore gitignore = ".gitignore" File.open(".gitignore", "a") do |f| f.puts f.puts "/deploy/chef/dna/generated.json" f.puts "/deploy/chef/dna/aliases.json" end end def add_git_submodule return unless File.directory?(".git") return if File.directory?("deploy/chef/recipes/cookbooks") sh "git submodule add #{@settings["COOKBOOK_REPOSITORY"]} deploy/chef/recipes/cookbooks #{@settings["COOKBOOK_BRANCH"]} >/dev/null 2>&1" end def copy_template Dir.chdir(TEMPLATE_PATH) do Dir["**/*"].each do |source| target = File.join(@destination, source) if File.directory?(source) FileUtils.mkdir_p target else content = File.read(source) content.gsub!(/\{\{([A-Z_]+)\}\}/){ @settings[$1] || "TODO" } File.open(target, "w") do |f| f << content end File.chmod(File.stat(source).mode, target) end end end end def sh(command) system command or raise ShellCommandError, command end end end
Version data entries
9 entries across 9 versions & 1 rubygems