Class: Puppet::ModuleTool::Metadata Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shared/puppet/module_tool/metadata.rb

Overview

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.

This class provides a data structure representing a module’s metadata.

Constant Summary collapse

DEFAULTS =

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.

{
  'name'         => nil,
  'version'      => nil,
  'author'       => nil,
  'summary'      => nil,
  'license'      => 'Apache-2.0',
  'source'       => '',
  'project_page' => nil,
  'issues_url'   => nil,
  'dependencies' => Set.new.freeze,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetadata

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 a new instance of Metadata.



27
28
29
30
# File 'lib/shared/puppet/module_tool/metadata.rb', line 27

def initialize
  @data = DEFAULTS.dup
  @data['dependencies'] = @data['dependencies'].dup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ 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.

Expose any metadata keys as callable reader methods.



109
110
111
112
# File 'lib/shared/puppet/module_tool/metadata.rb', line 109

def method_missing(name, *args)
  return @data[name.to_s] if @data.key? name.to_s
  super
end

Instance Attribute Details

#module_nameObject Also known as: name

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.



13
14
15
# File 'lib/shared/puppet/module_tool/metadata.rb', line 13

def module_name
  @module_name
end

Instance Method Details

#add_dependency(name, version_requirement = nil, repository = nil) ⇒ 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.

Validates the name and version_requirement for a dependency, then creates the Dependency and adds it. Returns the Dependency that was added.



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/shared/puppet/module_tool/metadata.rb', line 62

def add_dependency(name, version_requirement=nil, repository=nil)
  validate_name(name)
  validate_version_range(version_requirement) if version_requirement

  if dup = @data['dependencies'].find { |d| d.full_module_name == name && d.version_requirement != version_requirement }
    raise ArgumentError, "Dependency conflict for #{full_module_name}: Dependency #{name} was given conflicting version requirements #{version_requirement} and #{dup.version_requirement}. Verify that there are no duplicates in the metadata.json or the Modulefile."
  end

  dep = Dependency.new(name, version_requirement, repository)
  @data['dependencies'].add(dep)

  dep
end

#dashed_nameObject Also known as: full_module_name

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 a filesystem-friendly version of this module name.



33
34
35
# File 'lib/shared/puppet/module_tool/metadata.rb', line 33

def dashed_name
  @data['name'].tr('/', '-') if @data['name']
end

#dependenciesObject

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.



84
85
86
# File 'lib/shared/puppet/module_tool/metadata.rb', line 84

def dependencies
  @data['dependencies'].to_a
end

#descriptionObject

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.

Deprecated.

Provides an accessor for the now defunct ‘description’ property. This addresses a regression in Puppet 3.6.x where previously valid templates refering to the ‘description’ property were broken.



80
81
82
# File 'lib/shared/puppet/module_tool/metadata.rb', line 80

def description
  @data['description']
end

#release_nameObject

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 a string that uniquely represents this version of this module.



38
39
40
41
# File 'lib/shared/puppet/module_tool/metadata.rb', line 38

def release_name
  return nil unless @data['name'] && @data['version']
  [ dashed_name, @data['version'] ].join('-')
end

#to_hashObject Also known as: to_data_hash

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 a hash of the module’s metadata. Used by Puppet’s automated serialization routines.

See Also:

  • Network::FormatSupport#to_data_hash


92
93
94
# File 'lib/shared/puppet/module_tool/metadata.rb', line 92

def to_hash
  @data
end

#to_jsonObject

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.



97
98
99
100
101
102
103
104
105
106
# File 'lib/shared/puppet/module_tool/metadata.rb', line 97

def to_json
  data = @data.dup.merge('dependencies' => dependencies)

  contents = data.keys.map do |k|
    value = (JSON.pretty_generate(data[k]) rescue data[k].to_json)
    "#{k.to_json}: #{value}"
  end

  "{\n" + contents.join(",\n").gsub(/^/, '  ') + "\n}\n"
end

#update(data, with_dependencies = true) ⇒ 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.

Merges the current set of metadata with another metadata hash. This method also handles the validation of module names and versions, in an effort to be proactive about module publishing constraints.



49
50
51
52
53
54
55
56
57
# File 'lib/shared/puppet/module_tool/metadata.rb', line 49

def update(data, with_dependencies = true)
  process_name(data) if data['name']
  process_version(data) if data['version']
  process_source(data) if data['source']
  merge_dependencies(data) if with_dependencies && data['dependencies']

  @data.merge!(data)
  return self
end