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