Class: Puppet::Module::Plan Private

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

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

Class Method Summary collapse

Instance Method Summary collapse

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



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/puppet/module/plan.rb', line 117

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_fileObject (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.



114
115
116
# File 'lib/puppet/module/plan.rb', line 114

def 
  @metadata_file
end

#moduleObject (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.



114
115
116
# File 'lib/puppet/module/plan.rb', line 114

def module
  @module
end

#nameObject (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.



114
115
116
# File 'lib/puppet/module/plan.rb', line 114

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.



98
99
100
# File 'lib/puppet/module/plan.rb', line 98

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.

Returns:

  • (Boolean)


59
60
61
62
63
# File 'lib/puppet/module/plan.rb', line 59

def self.is_plan_name?(name)
  return true if name =~ /^[a-z][a-z0-9_]*$/

  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

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/puppet/module/plan.rb', line 66

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

  [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.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/puppet/module/plan.rb', line 102

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.



145
146
147
148
# File 'lib/puppet/module/plan.rb', line 145

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

#filesObject

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.



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

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

#metadataObject

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.



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

def 
  # Nothing to go here unless plans eventually support metadata.
  @metadata ||= {}
end

#validateObject

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.



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

def validate
  files
  true
end