Class: PDK::Generate::PuppetClass
- Inherits:
-
PuppetObject
- Object
- PuppetObject
- PDK::Generate::PuppetClass
- Defined in:
- lib/pdk/generate/puppet_class.rb
Constant Summary collapse
- OBJECT_TYPE =
:class
- PUPPET_STRINGS_TYPE =
'puppet_classes'.freeze
Instance Attribute Summary
Attributes inherited from PuppetObject
#module_dir, #object_name, #options
Instance Method Summary collapse
-
#target_object_path ⇒ String
Calculates the path to the .pp file that the new class will be written to.
-
#target_spec_path ⇒ String
Calculates the path to the file where the tests for the new class will be written.
-
#template_data ⇒ Hash{Symbol => Object}
Prepares the data needed to render the new Puppet class template.
Methods inherited from PuppetObject
#check_preconditions, class_name_from_object_name, #initialize, #module_metadata, #module_name, #object_type, puppet_strings_type, #render_file, #run, #spec_only?, #target_device_path, #target_type_path, #target_type_spec_path, #targets, #templates, #with_templates, #write_file
Constructor Details
This class inherits a constructor from PDK::Generate::PuppetObject
Instance Method Details
#target_object_path ⇒ String
Calculates the path to the .pp file that the new class will be written to.
23 24 25 26 27 28 29 30 |
# File 'lib/pdk/generate/puppet_class.rb', line 23 def target_object_path @target_pp_path ||= begin class_name_parts = object_name.split('::')[1..-1] class_name_parts << 'init' if class_name_parts.empty? "#{File.join(module_dir, 'manifests', *class_name_parts)}.pp" end end |
#target_spec_path ⇒ String
Calculates the path to the file where the tests for the new class will be written.
written.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pdk/generate/puppet_class.rb', line 37 def target_spec_path @target_spec_path ||= begin class_name_parts = object_name.split('::') # drop the module name if the object name contains multiple parts class_name_parts.delete_at(0) if class_name_parts.length > 1 "#{File.join(module_dir, 'spec', 'classes', *class_name_parts)}_spec.rb" end end |
#template_data ⇒ Hash{Symbol => Object}
Prepares the data needed to render the new Puppet class template.
provided to the class and class spec templates during rendering.
13 14 15 16 17 |
# File 'lib/pdk/generate/puppet_class.rb', line 13 def template_data data = { name: object_name } data end |