class ChefDK::Command::GeneratorCommands::CookbookCodeFile
## CookbookCodeFile
A base class for generators that add individual files to existing cookbooks.
Attributes
cookbook_path[R]
errors[R]
new_file_basename[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/cookbook_code_file.rb, line 34 def initialize(params) @params_valid = true @cookbook_full_path = nil @new_file_basename = nil @errors = [] @params = params super end
Public Instance Methods
cookbook_name()
click to toggle source
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 68 def cookbook_name File.basename(cookbook_path) end
cookbook_root()
click to toggle source
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 64 def cookbook_root File.dirname(cookbook_path) end
params_valid?()
click to toggle source
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 94 def params_valid? @params_valid end
read_and_validate_params()
click to toggle source
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 72 def read_and_validate_params arguments = parse_options(params) case arguments.size when 1 @new_file_basename = arguments[0] @cookbook_path = Dir.pwd validate_cookbook_path when 2 @cookbook_path = arguments[0] @new_file_basename = arguments[1] else @params_valid = false end end
run()
click to toggle source
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 43 def run read_and_validate_params if params_valid? setup_context chef_runner.converge else errors.each { |error| err("Error: #{error}") } parse_options(params) msg(opt_parser) 1 end end
setup_context()
click to toggle source
Calls superclass method
ChefDK::Command::GeneratorCommands::Base#setup_context
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 56 def setup_context super Generator.add_attr_to_context(:cookbook_root, cookbook_root) Generator.add_attr_to_context(:cookbook_name, cookbook_name) Generator.add_attr_to_context(:new_file_basename, new_file_basename) Generator.add_attr_to_context(:recipe_name, new_file_basename) end
validate_cookbook_path()
click to toggle source
# File lib/chef-dk/command/generator_commands/cookbook_code_file.rb, line 87 def validate_cookbook_path unless File.file?(File.join(cookbook_path, "metadata.rb")) @errors << "Directory #{cookbook_path} is not a cookbook" @params_valid = false end end