Class: ChefDK::Command::GeneratorCommands::Policyfile
- Defined in:
- lib/chef-dk/command/generator_commands/policyfile.rb
Instance Attribute Summary collapse
-
#new_file_basename ⇒ Object
readonly
Returns the value of attribute new_file_basename.
-
#policyfile_dir ⇒ Object
readonly
Returns the value of attribute policyfile_dir.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(*args) ⇒ Policyfile
constructor
A new instance of Policyfile.
- #params_valid? ⇒ Boolean
- #read_and_validate_params ⇒ Object
- #recipe ⇒ Object
- #run ⇒ Object
- #setup_context ⇒ Object
Methods inherited from Base
#chef_runner, #generator_cookbook_name, #generator_cookbook_path, #have_git?
Methods included from ChefDK::Configurable
#chef_config, #chefdk_config, #config_loader
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_chefdk_location, #omnibus_embedded_bin_dir, #omnibus_install?, #omnibus_root, #stderr, #stdout, #system_command
Constructor Details
#initialize(*args) ⇒ Policyfile
Returns a new instance of Policyfile.
33 34 35 36 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 33 def initialize(*args) super @params_valid = true end |
Instance Attribute Details
#new_file_basename ⇒ Object (readonly)
Returns the value of attribute new_file_basename.
30 31 32 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 30 def new_file_basename @new_file_basename end |
#policyfile_dir ⇒ Object (readonly)
Returns the value of attribute policyfile_dir.
31 32 33 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 31 def policyfile_dir @policyfile_dir end |
Instance Method Details
#params_valid? ⇒ Boolean
76 77 78 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 76 def params_valid? @params_valid end |
#read_and_validate_params ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 60 def read_and_validate_params arguments = (params) new_file_path = case arguments.size when 0 "Policyfile" when 1 arguments[0] else @params_valid = false return false end @new_file_basename = File.basename(new_file_path, ".rb") @policyfile_dir = File.(File.dirname(new_file_path)) end |
#recipe ⇒ Object
38 39 40 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 38 def recipe 'policyfile' end |
#run ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 48 def run read_and_validate_params if params_valid? setup_context chef_runner.converge 0 else msg() 1 end end |
#setup_context ⇒ Object
42 43 44 45 46 |
# File 'lib/chef-dk/command/generator_commands/policyfile.rb', line 42 def setup_context super Generator.add_attr_to_context(:policyfile_dir, policyfile_dir) Generator.add_attr_to_context(:new_file_basename, new_file_basename) end |