Class: Sambot::Chef::Generator
- Inherits:
-
Object
- Object
- Sambot::Chef::Generator
- Defined in:
- lib/sambot/chef/generator.rb
Class Method Summary collapse
- .bootstrap(config, path) ⇒ Object
- .bootstrap_centos(path) ⇒ Object
- .bootstrap_windows(path) ⇒ Object
- .exists!(path) ⇒ Object
- .from_templates(config, cloud, local_workflow, generated_files) ⇒ Object
- .generate_bootstrap_from_template(path, suffix) ⇒ Object
- .generate_bootstrap_scripts(config, cloud, local_workflow) ⇒ Object
- .generate_from_template(template_file, opts, config) ⇒ Object
- .valid_platform?(opts, config) ⇒ Boolean
Class Method Details
.bootstrap(config, path) ⇒ Object
24 25 26 27 |
# 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) ⇒ Object
16 17 18 |
# File 'lib/sambot/chef/generator.rb', line 16 def self.bootstrap_centos(path) generate_bootstrap_from_template(path, 'sh') end |
.bootstrap_windows(path) ⇒ Object
20 21 22 |
# File 'lib/sambot/chef/generator.rb', line 20 def self.bootstrap_windows(path) generate_bootstrap_from_template(path, 'ps1') end |
.exists!(path) ⇒ Object
37 38 39 40 |
# 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 |
.from_templates(config, cloud, local_workflow, generated_files) ⇒ Object
9 10 11 12 |
# 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 |
.generate_bootstrap_from_template(path, suffix) ⇒ Object
29 30 31 |
# 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) ⇒ Object
33 34 35 |
# 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) ⇒ Object
42 43 44 45 46 47 48 49 |
# 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) ⇒ Boolean
51 52 53 54 55 |
# 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 |