Class: Puppet::ModuleTool::Metadata Private
- Includes:
- Network::FormatSupport
- Defined in:
- lib/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, 'data_provider' => nil, }
Instance Attribute Summary collapse
- #module_name ⇒ Object (also: #name) private
Instance Method Summary collapse
-
#add_dependency(name, version_requirement = nil, repository = nil) ⇒ Object
private
Validates the name and version_requirement for a dependency, then creates the Dependency and adds it.
-
#dashed_name ⇒ Object
(also: #full_module_name)
private
Returns a filesystem-friendly version of this module name.
- #dependencies ⇒ Object private
- #description ⇒ Object deprecated private Deprecated.
-
#initialize ⇒ Metadata
constructor
private
A new instance of Metadata.
-
#method_missing(name, *args) ⇒ Object
private
Expose any metadata keys as callable reader methods.
-
#release_name ⇒ Object
private
Returns a string that uniquely represents this version of this module.
-
#to_hash ⇒ Object
(also: #to_data_hash)
private
Returns a hash of the module’s metadata.
- #to_json ⇒ Object private
-
#update(data) ⇒ Object
private
Merges the current set of metadata with another metadata hash.
Methods included from Network::FormatSupport
included, #mime, #render, #support_format?, #to_msgpack, #to_pson
Constructor Details
#initialize ⇒ Metadata
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.
29 30 31 32 |
# File 'lib/puppet/module_tool/metadata.rb', line 29 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.
112 113 114 115 |
# File 'lib/puppet/module_tool/metadata.rb', line 112 def method_missing(name, *args) return @data[name.to_s] if @data.key? name.to_s super end |
Instance Attribute Details
#module_name ⇒ Object 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.
14 15 16 |
# File 'lib/puppet/module_tool/metadata.rb', line 14 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.
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppet/module_tool/metadata.rb', line 65 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 %{module_name}: Dependency %{name} was given conflicting version requirements %{version_requirement} and %{dup_version}. Verify that there are no duplicates in the metadata.json.") % { module_name: full_module_name, name: name, version_requirement: version_requirement, dup_version: dup.version_requirement } end dep = Dependency.new(name, version_requirement, repository) @data['dependencies'].add(dep) dep end |
#dashed_name ⇒ Object 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.
35 36 37 |
# File 'lib/puppet/module_tool/metadata.rb', line 35 def dashed_name @data['name'].tr('/', '-') if @data['name'] end |
#dependencies ⇒ 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.
87 88 89 |
# File 'lib/puppet/module_tool/metadata.rb', line 87 def dependencies @data['dependencies'].to_a end |
#description ⇒ 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.
Provides an accessor for the now defunct ‘description’ property. This addresses a regression in Puppet 3.6.x where previously valid templates referring to the ‘description’ property were broken.
83 84 85 |
# File 'lib/puppet/module_tool/metadata.rb', line 83 def description @data['description'] end |
#release_name ⇒ 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.
Returns a string that uniquely represents this version of this module.
40 41 42 43 |
# File 'lib/puppet/module_tool/metadata.rb', line 40 def release_name return nil unless @data['name'] && @data['version'] [ dashed_name, @data['version'] ].join('-') end |
#to_hash ⇒ Object 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.
95 96 97 |
# File 'lib/puppet/module_tool/metadata.rb', line 95 def to_hash @data end |
#to_json ⇒ 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.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/puppet/module_tool/metadata.rb', line 100 def to_json data = @data.dup.merge('dependencies' => dependencies) contents = data.keys.map do |k| value = (Puppet::Util::Json.dump(data[k], :pretty => true) rescue data[k].to_json) %Q("#{k.to_s}": #{value}) end "{\n" + contents.join(",\n").gsub(/^/, ' ') + "\n}\n" end |
#update(data) ⇒ 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.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/puppet/module_tool/metadata.rb', line 51 def update(data) process_name(data) if data['name'] process_version(data) if data['version'] process_source(data) if data['source'] process_data_provider(data) if data['data_provider'] merge_dependencies(data) if data['dependencies'] @data.merge!(data) return self end |