Class: Bosh::Gen::Generators::JobGenerator
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- Bosh::Gen::Generators::JobGenerator
- Includes:
- Thor::Actions
- Defined in:
- lib/bosh/gen/generators/job_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_name ⇒ Object
- #check_purpose ⇒ Object
- #check_root_is_release ⇒ Object
- #job_specification ⇒ Object
-
#template_files ⇒ Object
copy the thor template files into the bosh release to be bosh templates that’s right, templates (.tt) can become templates (.erb).
- #warn_missing_dependencies ⇒ Object
Class Method Details
.source_root ⇒ Object
13 14 15 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 13 def self.source_root File.join(File.dirname(__FILE__), "job_generator", "templates") end |
Instance Method Details
#check_name ⇒ Object
23 24 25 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 23 def check_name raise Thor::Error.new("'#{job_name}' is not a valid BOSH id") unless job_name.bosh_valid_id? end |
#check_purpose ⇒ Object
27 28 29 30 31 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 27 def check_purpose unless valid_purposes.include?(purpose) raise Thor::Error.new("'#{purpose}' is not a valid job purpose of #{valid_purposes.inspect}") end end |
#check_root_is_release ⇒ Object
17 18 19 20 21 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 17 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 ⇒ Object
63 64 65 66 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 63 def job_specification config = { "name" => job_name, "packages" => dependencies, "templates" => @template_files } create_file job_dir("spec"), YAML.dump(config) end |
#template_files ⇒ Object
copy the thor template files into the bosh release to be bosh templates that’s right, templates (.tt) can become templates (.erb)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 44 def template_files generator_job_templates_path = File.join(self.class.source_root, "jobs/%job_name%_#{purpose}") directory "jobs/%job_name%_#{purpose}", "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 `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 ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/bosh/gen/generators/job_generator.rb', line 33 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 |