Class: ChefDK::Command::GeneratorCommands::HabiChef
- Inherits:
-
Base
- Object
- Base
- ChefDK::Command::GeneratorCommands::HabiChef
- Defined in:
- lib/chef-dk/command/generator_commands/habichef.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#habichef_name_or_path ⇒ Object
readonly
Returns the value of attribute habichef_name_or_path.
Instance Method Summary collapse
- #habichef_full_path ⇒ Object
- #habichef_name ⇒ Object
- #habichef_path_in_git_repo? ⇒ Boolean
- #habichef_root ⇒ Object
-
#initialize(params) ⇒ HabiChef
constructor
A new instance of HabiChef.
- #params_valid? ⇒ Boolean
- #read_and_validate_params ⇒ Object
- #recipe ⇒ Object
- #run ⇒ Object
- #setup_context ⇒ Object
Constructor Details
#initialize(params) ⇒ HabiChef
Returns a new instance of HabiChef.
18 19 20 21 22 23 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 18 def initialize(params) @params_valid = true @habichef_name = nil @verbose = false super end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
13 14 15 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 13 def errors @errors end |
#habichef_name_or_path ⇒ Object (readonly)
Returns the value of attribute habichef_name_or_path.
14 15 16 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 14 def habichef_name_or_path @habichef_name_or_path end |
Instance Method Details
#habichef_full_path ⇒ Object
54 55 56 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 54 def habichef_full_path File. habichef_name_or_path, Dir.pwd end |
#habichef_name ⇒ Object
46 47 48 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 46 def habichef_name File.basename habichef_full_path end |
#habichef_path_in_git_repo? ⇒ Boolean
73 74 75 76 77 78 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 73 def habichef_path_in_git_repo? Pathname.new(habichef_full_path).ascend do |dir| return true if File.directory?(File.join(dir.to_s, ".git")) end false end |
#habichef_root ⇒ Object
50 51 52 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 50 def habichef_root File.dirname habichef_full_path end |
#params_valid? ⇒ Boolean
69 70 71 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 69 def params_valid? @params_valid end |
#read_and_validate_params ⇒ Object
58 59 60 61 62 63 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 58 def read_and_validate_params arguments = (params) @habichef_name_or_path = arguments[0] @params_valid = false unless @habichef_name_or_path true end |
#recipe ⇒ Object
65 66 67 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 65 def recipe 'habichef' end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 25 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}" end |
#setup_context ⇒ Object
39 40 41 42 43 44 |
# File 'lib/chef-dk/command/generator_commands/habichef.rb', line 39 def setup_context super Generator.add_attr_to_context(:habichef_name, habichef_name) Generator.add_attr_to_context(:habichef_root, habichef_root) Generator.add_attr_to_context(:skip_git_init, habichef_path_in_git_repo?) end |