Class: ChefDK::Command::GeneratorCommands::CookbookCodeFile
- Defined in:
- lib/chef-dk/command/generator_commands.rb
Overview
## CookbookCodeFile A base class for generators that add individual files to existing cookbooks.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cookbook_path ⇒ Object
readonly
Returns the value of attribute cookbook_path.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#new_file_basename ⇒ Object
readonly
Returns the value of attribute new_file_basename.
Attributes inherited from Base
Instance Method Summary collapse
- #cookbook_name ⇒ Object
- #cookbook_root ⇒ Object
-
#initialize(params) ⇒ CookbookCodeFile
constructor
A new instance of CookbookCodeFile.
- #params_valid? ⇒ Boolean
- #read_and_validate_params ⇒ Object
- #run ⇒ Object
- #setup_context ⇒ Object
- #validate_cookbook_path ⇒ Object
Methods inherited from Base
#chef_runner, #generator_context, #generator_cookbook_path, #have_git?
Methods inherited from Base
#needs_help?, #needs_version?, #run_with_default_options
Methods included from Helpers
#err, #msg, #omnibus_apps_dir, #omnibus_bin_dir, #omnibus_embedded_bin_dir, #omnibus_root, #stderr, #stdout, #system_command
Constructor Details
#initialize(params) ⇒ CookbookCodeFile
Returns a new instance of CookbookCodeFile.
267 268 269 270 271 272 273 |
# File 'lib/chef-dk/command/generator_commands.rb', line 267 def initialize(params) @params_valid = true @cookbook_full_path = nil @new_file_basename = nil @errors = [] super end |
Instance Attribute Details
#cookbook_path ⇒ Object (readonly)
Returns the value of attribute cookbook_path.
262 263 264 |
# File 'lib/chef-dk/command/generator_commands.rb', line 262 def cookbook_path @cookbook_path end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
261 262 263 |
# File 'lib/chef-dk/command/generator_commands.rb', line 261 def errors @errors end |
#new_file_basename ⇒ Object (readonly)
Returns the value of attribute new_file_basename.
263 264 265 |
# File 'lib/chef-dk/command/generator_commands.rb', line 263 def new_file_basename @new_file_basename end |
Instance Method Details
#cookbook_name ⇒ Object
299 300 301 |
# File 'lib/chef-dk/command/generator_commands.rb', line 299 def cookbook_name File.basename(cookbook_path) end |
#cookbook_root ⇒ Object
295 296 297 |
# File 'lib/chef-dk/command/generator_commands.rb', line 295 def cookbook_root File.dirname(cookbook_path) end |
#params_valid? ⇒ Boolean
325 326 327 |
# File 'lib/chef-dk/command/generator_commands.rb', line 325 def params_valid? @params_valid end |
#read_and_validate_params ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/chef-dk/command/generator_commands.rb', line 303 def read_and_validate_params arguments = (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 ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/chef-dk/command/generator_commands.rb', line 275 def run read_and_validate_params if params_valid? setup_context chef_runner.converge else errors.each {|error| err("Error: #{error}") } msg(opt_parser) 1 end end |
#setup_context ⇒ Object
288 289 290 291 292 293 |
# File 'lib/chef-dk/command/generator_commands.rb', line 288 def setup_context super generator_context.cookbook_root = cookbook_root generator_context.cookbook_name = cookbook_name generator_context.new_file_basename = new_file_basename end |
#validate_cookbook_path ⇒ Object
318 319 320 321 322 323 |
# File 'lib/chef-dk/command/generator_commands.rb', line 318 def validate_cookbook_path unless File.directory?(File.join(cookbook_path, "recipes")) @errors << "Directory #{cookbook_path} is not a cookbook" @params_valid = false end end |