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


110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/puppet/module/plan.rb', line 110

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

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


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

def 
  @metadata
end

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


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

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.


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

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.


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

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.


91
92
93
# File 'lib/puppet/module/plan.rb', line 91

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)

54
55
56
57
# File 'lib/puppet/module/plan.rb', line 54

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

Returns:

  • (Boolean)

60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/puppet/module/plan.rb', line 60

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.


95
96
97
98
99
100
101
102
103
104
105
# File 'lib/puppet/module/plan.rb', line 95

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.


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

def ==(other)
  self.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.


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

def files
  @files ||= self.class.find_files(@name, @plan_files)
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.


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

def validate
  files
  true
end