class Puppet::Module::Plan
Constants
- ALLOWED_EXTENSIONS
- RESERVED_DATA_TYPES
- RESERVED_WORDS
Attributes
metadata[R]
metadata_file[R]
module[R]
name[R]
Public Class Methods
find_files(name, plan_files)
click to toggle source
# File lib/puppet/module/plan.rb 91 def self.find_files(name, plan_files) 92 find_implementations(name, plan_files) 93 end
is_plan_name?(name)
click to toggle source
# File lib/puppet/module/plan.rb 54 def self.is_plan_name?(name) 55 return true if name =~ /^[a-z][a-z0-9_]*$/ 56 return false 57 end
is_plans_filename?(path)
click to toggle source
Determine whether a plan file has a legal name and extension
# File lib/puppet/module/plan.rb 60 def self.is_plans_filename?(path) 61 name = File.basename(path, '.*') 62 ext = File.extname(path) 63 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) 64 unless ALLOWED_EXTENSIONS.include? ext 65 return [false, _("Plan name cannot have extension %{ext}, must be .pp or .yaml") % { ext: ext }] 66 end 67 if RESERVED_WORDS.include?(name) 68 return [false, _("Plan name cannot be a reserved word, but was '%{name}'") % { name: name }] 69 end 70 if RESERVED_DATA_TYPES.include?(name) 71 return [false, _("Plan name cannot be a Puppet data type, but was '%{name}'") % { name: name }] 72 end 73 return [true] 74 end
new(pup_module, plan_name, plan_files)
click to toggle source
file paths must be relative to the modules plan directory
# File lib/puppet/module/plan.rb 110 def initialize(pup_module, plan_name, plan_files) 111 valid, reason = Puppet::Module::Plan.is_plans_filename?(plan_files.first) 112 unless valid 113 raise InvalidName.new(plan_name, reason) 114 end 115 116 name = plan_name == "init" ? pup_module.name : "#{pup_module.name}::#{plan_name}" 117 118 @module = pup_module 119 @name = name 120 @metadata_file = metadata_file 121 @plan_files = plan_files || [] 122 end
plans_in_module(pup_module)
click to toggle source
# File lib/puppet/module/plan.rb 95 def self.plans_in_module(pup_module) 96 # Search e.g. 'modules/<pup_module>/plans' for all plans 97 plan_files = Dir.glob(File.join(pup_module.plans_directory, '*')) 98 .keep_if { |f| valid, _ = is_plans_filename?(f); valid } 99 100 plans = plan_files.group_by { |f| plan_name_from_path(f) } 101 102 plans.map do |plan, plan_filenames| 103 new_with_files(pup_module, plan, plan_filenames) 104 end 105 end
Private Class Methods
find_implementations(name, plan_files)
click to toggle source
Executables list should contain the full path of all possible implementation files
# File lib/puppet/module/plan.rb 77 def self.find_implementations(name, plan_files) 78 basename = name.split('::')[1] || 'init' 79 80 # If implementations isn't defined, then we use executables matching the 81 # plan name, and only one may exist. 82 implementations = plan_files.select { |impl| File.basename(impl, '.*') == basename } 83 84 # Select .pp before .yaml, since .pp comes before .yaml alphabetically. 85 chosen = implementations.sort.first 86 87 [{ "name" => File.basename(chosen), "path" => chosen }] 88 end
new_with_files(pup_module, name, plan_files)
click to toggle source
# File lib/puppet/module/plan.rb 148 def self.new_with_files(pup_module, name, plan_files) 149 Puppet::Module::Plan.new(pup_module, name, plan_files) 150 end
plan_name_from_path(path)
click to toggle source
Abstracted here so we can add support for subdirectories later
# File lib/puppet/module/plan.rb 154 def self.plan_name_from_path(path) 155 return File.basename(path, '.*') 156 end
Public Instance Methods
==(other)
click to toggle source
# File lib/puppet/module/plan.rb 138 def ==(other) 139 self.name == other.name && 140 self.module == other.module 141 end
files()
click to toggle source
# File lib/puppet/module/plan.rb 129 def files 130 @files ||= self.class.find_files(@name, @plan_files) 131 end
validate()
click to toggle source
# File lib/puppet/module/plan.rb 133 def validate 134 files 135 true 136 end
Private Instance Methods
environment_name()
click to toggle source
# File lib/puppet/module/plan.rb 143 def environment_name 144 @module.environment.respond_to?(:name) ? @module.environment.name : 'production' 145 end