Class: PDK::Generate::Provider
- Inherits:
-
PuppetObject
- Object
- PuppetObject
- PDK::Generate::Provider
- Defined in:
- lib/pdk/generate/provider.rb
Constant Summary collapse
- OBJECT_TYPE =
:provider
Instance Attribute Summary
Attributes inherited from PuppetObject
#module_dir, #object_name, #options
Class Method Summary collapse
-
.class_name_from_object_name(object_name) ⇒ Object
transform a object name into a ruby class name.
Instance Method Summary collapse
- #check_preconditions ⇒ Object
- #raise_precondition_error(error) ⇒ Object
-
#target_object_path ⇒ String
The path where the new provider will be written.
-
#target_spec_path ⇒ String
will be written.
-
#target_type_path ⇒ String
The path where the new type will be written.
-
#target_type_spec_path ⇒ String
The path where the tests for the new type will be written.
-
#template_data ⇒ Hash{Symbol => Object}
Prepares the data needed to render the new defined type template.
Methods inherited from PuppetObject
#initialize, #module_metadata, #module_name, #object_type, #render_file, #run, #templates, #with_templates, #write_file
Constructor Details
This class inherits a constructor from PDK::Generate::PuppetObject
Class Method Details
.class_name_from_object_name(object_name) ⇒ Object
transform a object name into a ruby class name
77 78 79 |
# File 'lib/pdk/generate/provider.rb', line 77 def self.class_name_from_object_name(object_name) object_name.to_s.split('_').map(&:capitalize).join end |
Instance Method Details
#check_preconditions ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/pdk/generate/provider.rb', line 27 def check_preconditions super # These preconditions can be removed once the pdk-templates are carrying the puppet-resource_api gem by default, and have switched # the default mock_with value. sync_path = PDK::Util.find_upwards('.sync.yml') if sync_path.nil? raise_precondition_error(_('.sync.yml not found')) end sync = YAML.load_file(sync_path) if !sync.is_a? Hash raise_precondition_error(_('.sync.yml contents is not a Hash')) elsif !sync.key? 'Gemfile' raise_precondition_error(_('Gemfile configuration not found')) elsif !sync['Gemfile'].key? 'optional' raise_precondition_error(_('Gemfile.optional configuration not found')) elsif !sync['Gemfile']['optional'].key? ':development' raise_precondition_error(_('Gemfile.optional.:development configuration not found')) elsif sync['Gemfile']['optional'][':development'].none? { |g| g['gem'] == 'puppet-resource_api' } raise_precondition_error(_('puppet-resource_api not found in the Gemfile config')) elsif !sync.key? 'spec/spec_helper.rb' raise_precondition_error(_('spec/spec_helper.rb configuration not found')) elsif !sync['spec/spec_helper.rb'].key? 'mock_with' raise_precondition_error(_('spec/spec_helper.rb.mock_with configuration not found')) elsif !sync['spec/spec_helper.rb']['mock_with'] == ':rspec' raise_precondition_error(_('spec/spec_helper.rb.mock_with not set to \':rspec\'')) end end |
#raise_precondition_error(error) ⇒ Object
22 23 24 25 |
# File 'lib/pdk/generate/provider.rb', line 22 def raise_precondition_error(error) raise PDK::CLI::ExitWithError, _('%{error}: Creating a provider needs some local configuration in your module.' \ ' Please follow the docs at https://github.com/puppetlabs/puppet-resource_api#getting-started.') % { error: error } end |
#target_object_path ⇒ String
Returns the path where the new provider will be written.
56 57 58 |
# File 'lib/pdk/generate/provider.rb', line 56 def target_object_path @target_object_path ||= File.join(module_dir, 'lib', 'puppet', 'provider', object_name, object_name) + '.rb' end |
#target_spec_path ⇒ String
will be written.
67 68 69 |
# File 'lib/pdk/generate/provider.rb', line 67 def target_spec_path @target_spec_path ||= File.join(module_dir, 'spec', 'unit', 'puppet', 'provider', object_name, object_name) + '_spec.rb' end |
#target_type_path ⇒ String
Returns the path where the new type will be written.
61 62 63 |
# File 'lib/pdk/generate/provider.rb', line 61 def target_type_path @target_type_path ||= File.join(module_dir, 'lib', 'puppet', 'type', object_name) + '.rb' end |
#target_type_spec_path ⇒ String
Returns the path where the tests for the new type will be written.
72 73 74 |
# File 'lib/pdk/generate/provider.rb', line 72 def target_type_spec_path @target_type_spec_path ||= File.join(module_dir, 'spec', 'unit', 'puppet', 'type', object_name) + '_spec.rb' end |
#template_data ⇒ Hash{Symbol => Object}
Prepares the data needed to render the new defined type template.
provided to the defined type and defined type spec templates during rendering.
13 14 15 16 17 18 19 20 |
# File 'lib/pdk/generate/provider.rb', line 13 def template_data data = { name: object_name, provider_class: Provider.class_name_from_object_name(object_name), } data end |