Class: Puppet::Module::Plan Private
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: Error, InvalidFile, InvalidMetadata, InvalidName, InvalidPlan, PlanNotFound
Constant Summary collapse
- ALLOWED_EXTENSIONS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w{.pp .yaml}
- RESERVED_WORDS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w{and application attr case class consumes default else elsif environment false function if import in inherits node or private produces site true type undef unless}
- RESERVED_DATA_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w{any array boolean catalogentry class collection callable data default enum float hash integer numeric optional pattern resource runtime scalar string struct tuple type undef variant}
Instance Attribute Summary collapse
- #metadata_file ⇒ Object readonly private
- #module ⇒ Object readonly private
- #name ⇒ Object readonly private
Class Method Summary collapse
- .find_files(name, plan_files) ⇒ Object private
- .is_plan_name?(name) ⇒ Boolean private
-
.is_plans_filename?(path) ⇒ Boolean
private
Determine whether a plan file has a legal name and extension.
- .plans_in_module(pup_module) ⇒ Object private
Instance Method Summary collapse
- #==(other) ⇒ Object private
- #files ⇒ Object private
-
#initialize(pup_module, plan_name, plan_files) ⇒ Plan
constructor
private
file paths must be relative to the modules plan directory.
- #metadata ⇒ Object private
- #validate ⇒ Object private
Constructor Details
#initialize(pup_module, plan_name, plan_files) ⇒ Plan
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.
file paths must be relative to the modules plan directory
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/puppet/module/plan.rb', line 111 def initialize(pup_module, plan_name, plan_files) valid, reason = Puppet::Module::Plan.is_plans_filename?(plan_files.first) unless valid raise InvalidName.new(plan_name, reason) end name = plan_name == "init" ? pup_module.name : "#{pup_module.name}::#{plan_name}" @module = pup_module @name = name @metadata_file = @plan_files = plan_files || [] end |
Instance Attribute Details
#metadata_file ⇒ Object (readonly)
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.
108 109 110 |
# File 'lib/puppet/module/plan.rb', line 108 def @metadata_file end |
#module ⇒ Object (readonly)
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.
108 109 110 |
# File 'lib/puppet/module/plan.rb', line 108 def module @module end |
#name ⇒ Object (readonly)
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.
108 109 110 |
# File 'lib/puppet/module/plan.rb', line 108 def name @name end |
Class Method Details
.find_files(name, plan_files) ⇒ 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.
92 93 94 |
# File 'lib/puppet/module/plan.rb', line 92 def self.find_files(name, plan_files) find_implementations(name, plan_files) end |
.is_plan_name?(name) ⇒ Boolean
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.
55 56 57 58 |
# File 'lib/puppet/module/plan.rb', line 55 def self.is_plan_name?(name) return true if name =~ /^[a-z][a-z0-9_]*$/ return false end |
.is_plans_filename?(path) ⇒ Boolean
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.
Determine whether a plan file has a legal name and extension
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/puppet/module/plan.rb', line 61 def self.is_plans_filename?(path) name = File.basename(path, '.*') ext = File.extname(path) return [false, _("Plan names must start with a lowercase letter and be composed of only lowercase letters, numbers, and underscores")] unless is_plan_name?(name) unless ALLOWED_EXTENSIONS.include? ext return [false, _("Plan name cannot have extension %{ext}, must be .pp or .yaml") % { ext: ext }] end if RESERVED_WORDS.include?(name) return [false, _("Plan name cannot be a reserved word, but was '%{name}'") % { name: name }] end if RESERVED_DATA_TYPES.include?(name) return [false, _("Plan name cannot be a Puppet data type, but was '%{name}'") % { name: name }] end return [true] end |
.plans_in_module(pup_module) ⇒ 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.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/puppet/module/plan.rb', line 96 def self.plans_in_module(pup_module) # Search e.g. 'modules/<pup_module>/plans' for all plans plan_files = Dir.glob(File.join(pup_module.plans_directory, '*')) .keep_if { |f| valid, _ = is_plans_filename?(f); valid } plans = plan_files.group_by { |f| plan_name_from_path(f) } plans.map do |plan, plan_filenames| new_with_files(pup_module, plan, plan_filenames) end end |
Instance Method Details
#==(other) ⇒ 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.
139 140 141 142 |
# File 'lib/puppet/module/plan.rb', line 139 def ==(other) self.name == other.name && self.module == other.module end |
#files ⇒ 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.
130 131 132 |
# File 'lib/puppet/module/plan.rb', line 130 def files @files ||= self.class.find_files(@name, @plan_files) end |
#metadata ⇒ 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.
125 126 127 128 |
# File 'lib/puppet/module/plan.rb', line 125 def # Nothing to go here unless plans eventually support metadata. @metadata ||= {} end |
#validate ⇒ 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.
134 135 136 137 |
# File 'lib/puppet/module/plan.rb', line 134 def validate files true end |