Class: PuppetMetadata::Metadata
- Inherits:
-
Object
- Object
- PuppetMetadata::Metadata
- Defined in:
- lib/puppet_metadata/metadata.rb
Overview
An abstraction over Puppet metadata
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#dependencies ⇒ Hash[String, SemanticPuppet::VersionRange]
A hash representation of the dependencies.
- #eol_operatingsystems(at = nil) ⇒ Hash[String, Array[String]]
-
#github_actions(options) ⇒ PuppetMetadata::GithubActions
A GithubActions instance.
-
#initialize(metadata, validate = true) ⇒ Metadata
constructor
A new instance of Metadata.
-
#license ⇒ String
The license.
-
#name ⇒ String
The name.
-
#operatingsystems ⇒ Hash[String, Array[String]]
The supported operating system and its major releases.
-
#os_release_supported?(operatingsystem, release) ⇒ Boolean
Returns whether an operating system’s release is supported.
-
#puppet_major_versions ⇒ Array[Integer]
Supported major Puppet versions.
-
#requirements ⇒ Hash[String, SemanticPuppet::VersionRange]
A hash representation of the requirements.
- #satisfies_dependency?(name, version) ⇒ Boolean
- #satisfies_requirement?(name, version) ⇒ Boolean
-
#version ⇒ String
The version.
Constructor Details
#initialize(metadata, validate = true) ⇒ Metadata
Returns a new instance of Metadata.
34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet_metadata/metadata.rb', line 34 def initialize(, validate = true) if validate require 'metadata_json_lint' schema_errors = MetadataJsonLint::Schema.new.validate() raise InvalidMetadataException, schema_errors if schema_errors.any? end @metadata = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
23 24 25 |
# File 'lib/puppet_metadata/metadata.rb', line 23 def @metadata end |
Instance Method Details
#dependencies ⇒ Hash[String, SemanticPuppet::VersionRange]
A hash representation of the dependencies
Every element in the original array is converted. The name is used as a key while version_requirement is used as a value. No value indicates any version is accepted.
178 179 180 |
# File 'lib/puppet_metadata/metadata.rb', line 178 def dependencies @dependencies ||= build_version_requirement_hash(['dependencies']) end |
#eol_operatingsystems(at = nil) ⇒ Hash[String, Array[String]]
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/puppet_metadata/metadata.rb', line 97 def (at = nil) at ||= Date.today unsupported = .map do |os, rels| next unless rels eol = rels.select { |rel| OperatingSystem.eol?(os, rel, at) } [os, eol] if eol.any? end unsupported.compact.to_h end |
#github_actions(options) ⇒ PuppetMetadata::GithubActions
Returns A GithubActions instance.
191 192 193 |
# File 'lib/puppet_metadata/metadata.rb', line 191 def github_actions() PuppetMetadata::GithubActions.new(self, ) end |
#license ⇒ String
The license
58 59 60 |
# File 'lib/puppet_metadata/metadata.rb', line 58 def license ['license'] end |
#name ⇒ String
The name
46 47 48 |
# File 'lib/puppet_metadata/metadata.rb', line 46 def name ['name'] end |
#operatingsystems ⇒ Hash[String, Array[String]]
Returns The supported operating system and its major releases.
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet_metadata/metadata.rb', line 64 def @operatingsystems ||= begin return {} if ['operatingsystem_support'].nil? supported = ['operatingsystem_support'].map do |os| next unless os['operatingsystem'] [os['operatingsystem'], os['operatingsystemrelease']] end supported.compact.to_h end end |
#os_release_supported?(operatingsystem, release) ⇒ Boolean
Returns whether an operating system’s release is supported
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/puppet_metadata/metadata.rb', line 83 def os_release_supported?(, release) # If no OS is present, everything is supported. An example of this is # modules with only functions. return true if .empty? # if the key present, nil indicates all releases are supported return false unless .key?() releases = [] releases.nil? || releases.include?(release) end |
#puppet_major_versions ⇒ Array[Integer]
Returns Supported major Puppet versions.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/puppet_metadata/metadata.rb', line 142 def puppet_major_versions requirement = requirements['puppet'] raise Exception, 'No Puppet requirement found' unless requirement # Current latest major is 7. It is highly recommended that modules # actually specify exact bounds, but this prevents an infinite loop. end_major = (requirement.end == SemanticPuppet::Version::MAX) ? 7 : requirement.end.major (requirement.begin.major..end_major).select do |major| requirement.include?(SemanticPuppet::Version.new(major, 0, 0)) || requirement.include?(SemanticPuppet::Version.new(major, 99, 99)) end end |
#requirements ⇒ Hash[String, SemanticPuppet::VersionRange]
A hash representation of the requirements
Every element in the original array is converted. The name is used as a key while version_requirement is used as a value. No value indicates any version is accepted.
129 130 131 |
# File 'lib/puppet_metadata/metadata.rb', line 129 def requirements @requirements ||= build_version_requirement_hash(['requirements']) end |
#satisfies_dependency?(name, version) ⇒ Boolean
185 186 187 |
# File 'lib/puppet_metadata/metadata.rb', line 185 def satisfies_dependency?(name, version) matches?(dependencies[name], version) end |
#satisfies_requirement?(name, version) ⇒ Boolean
136 137 138 |
# File 'lib/puppet_metadata/metadata.rb', line 136 def satisfies_requirement?(name, version) matches?(requirements[name], version) end |
#version ⇒ String
The version
52 53 54 |
# File 'lib/puppet_metadata/metadata.rb', line 52 def version ['version'] end |