class ChefDK::Command::GeneratorCommands::BuildCookbook
Attributes
cookbook_name_or_path[R]
errors[R]
Public Class Methods
new(params)
click to toggle source
Calls superclass method
ChefDK::Command::GeneratorCommands::Base::new
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 40 def initialize(params) @params_valid = true @cookbook_name = nil super end
Public Instance Methods
build_cookbook_parent_is_cookbook?()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 79 def build_cookbook_parent_is_cookbook? metadata_json_path = File.join(workflow_project_dir, "metadata.json") metadata_rb_path = File.join(workflow_project_dir, "metadata.rb") File.exist?(metadata_json_path) || File.exist?(metadata_rb_path) end
params_valid?()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 119 def params_valid? @params_valid end
pipeline()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 71 def pipeline config[:pipeline] end
read_and_validate_params()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 111 def read_and_validate_params arguments = parse_options(params) @cookbook_name_or_path = arguments[0] unless @cookbook_name_or_path @params_valid = false end end
recipe()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 75 def recipe "build_cookbook" end
run()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 46 def run read_and_validate_params if params_valid? setup_context chef_runner.converge 0 else err(opt_parser) 1 end rescue ChefDK::ChefRunnerError => e err("ERROR: #{e}") 1 end
setup_context()
click to toggle source
Calls superclass method
ChefDK::Command::GeneratorCommands::Base#setup_context
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 61 def setup_context super Generator.add_attr_to_context(:workflow_project_dir, workflow_project_dir) Generator.add_attr_to_context(:workflow_project_git_initialized, workflow_project_git_initialized?) Generator.add_attr_to_context(:build_cookbook_parent_is_cookbook, build_cookbook_parent_is_cookbook?) Generator.add_attr_to_context(:pipeline, pipeline) end
workflow_project_dir()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 86 def workflow_project_dir project_dir = File.expand_path(cookbook_name_or_path, Dir.pwd) # Detect if we were invoked with arguments like # # chef generate build-cookbook project/.delivery/build_cookbook # # If so, normalize paths so we don't make a directory structure like # `.delivery/.delivery/build_cookbook`. # # Note that we don't check the name of the build cookbook the user # asked for and we hard-code to naming it "build_cookbook". We also # don't catch the case that the user requested something like # `project/.delivery/build_cookbook/extra-thing-that-shouldn't-be-here` Pathname.new(project_dir).ascend do |dir| if File.basename(dir) == ".delivery" project_dir = File.dirname(dir) end end project_dir end
workflow_project_git_initialized?()
click to toggle source
# File lib/chef-dk/command/generator_commands/build_cookbook.rb, line 107 def workflow_project_git_initialized? File.exist?(File.join(workflow_project_dir, ".git")) end