Class: Puppet::Module::Plan

Inherits:
Object show all
Defined in:
lib/puppet/module/plan.rb

Defined Under Namespace

Classes: Error, InvalidFile, InvalidMetadata, InvalidName, InvalidPlan, PlanNotFound

Constant Summary collapse

ALLOWED_EXTENSIONS =
%w{.pp .yaml}
RESERVED_WORDS =
%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 =
%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}
MOUNTS =
%w[lib files plans]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pup_module, plan_name, plan_files) ⇒ Plan

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
   = 
  @plan_files = plan_files || []
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata


108
109
110
# File 'lib/puppet/module/plan.rb', line 108

def 
  
end

#metadata_fileObject (readonly)

Returns the value of attribute metadata_file


108
109
110
# File 'lib/puppet/module/plan.rb', line 108

def 
  
end

#moduleObject (readonly)

Returns the value of attribute module


108
109
110
# File 'lib/puppet/module/plan.rb', line 108

def module
  @module
end

#nameObject (readonly)

Returns the value of attribute name


108
109
110
# File 'lib/puppet/module/plan.rb', line 108

def name
  @name
end

Class Method Details

.find_files(name, plan_files) ⇒ Object


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


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

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


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


139
140
141
142
# File 'lib/puppet/module/plan.rb', line 139

def ==(other)
  self.name == other.name &&
  self.module == other.module
end

#filesObject


130
131
132
# File 'lib/puppet/module/plan.rb', line 130

def files
  @files ||= self.class.find_files(@name, @plan_files)
end

#validateObject


134
135
136
137
# File 'lib/puppet/module/plan.rb', line 134

def validate
  files
  true
end