Class: Puppet::ModuleTool::Metadata Private

Inherits:
Object
  • Object
show all
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' => [].freeze,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Network::FormatSupport

included, #mime, #render, #support_format?, #to_msgpack, #to_pson

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.



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

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.



89
90
91
92
# File 'lib/puppet/module_tool/metadata.rb', line 89

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.



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

def module_name
  @module_name
end

Instance Method Details

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



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

def dashed_name
  @data['name'].tr('/', '-') if @data['name']
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.



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

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.



63
64
65
# File 'lib/puppet/module_tool/metadata.rb', line 63

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.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/puppet/module_tool/metadata.rb', line 68

def to_json
  # This is used to simulate an ordered hash.  In particular, some keys
  # are promoted to the top of the serialized hash (while others are
  # demoted) for human-friendliness.
  #
  # This particularly works around the lack of ordered hashes in 1.8.7.
  promoted_keys = %w[ name version author summary license source ]
  demoted_keys = %w[ dependencies ]
  keys = @data.keys
  keys -= promoted_keys
  keys -= demoted_keys

  contents = (promoted_keys + keys + demoted_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) ⇒ 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.



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

def update(data)
  process_name(data) if data['name']
  process_version(data) if data['version']
  process_source(data) if data['source']

  @data.merge!(data)
  return self
end