Class: PDK::Generate::ResourceAPIObject Abstract
- Inherits:
-
PuppetObject
- Object
- PuppetObject
- PDK::Generate::ResourceAPIObject
- Defined in:
- lib/pdk/generate/resource_api_object.rb
Overview
An abstract class for generated objects that require the Puppet Resource API Gem
Instance Attribute Summary
Attributes inherited from PuppetObject
#context, #object_name, #options
Instance Method Summary collapse
-
#check_preconditions ⇒ Object
:nocov: This is tested in spec/acceptance/new_transport_spec.rb.
-
#raise_precondition_error(error) ⇒ Object
private
Helper method to raise an error if the Resource API is not available.
Methods inherited from PuppetObject
#can_run?, #friendly_name, #initialize, #module_name, #non_template_files, #run, #spec_only?, #stage_change, #stage_changes, #template_data, #template_files, #templates, #update_manager_instance, #with_templates
Constructor Details
This class inherits a constructor from PDK::Generate::PuppetObject
Instance Method Details
#check_preconditions ⇒ Object
:nocov: This is tested in spec/acceptance/new_transport_spec.rb
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/pdk/generate/resource_api_object.rb', line 11 def check_preconditions super # Note that these preconditions are only applicable to the current (V1) template rendering layout and will need to be changed # when additional template renderers are introduced. # # 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Helper method to raise an error if the Resource API is not available
45 46 47 48 49 50 51 |
# File 'lib/pdk/generate/resource_api_object.rb', line 45 def raise_precondition_error(error) raise PDK::CLI::ExitWithError, _('%{error}: Creating a %{thing_name} needs some local configuration in your module.' \ ' Please follow the docs at https://puppet.com/docs/puppet/latest/create_types_and_providers_resource_api.html') % { thing_name: friendly_name, error: error, } end |