Class: PuppetMetadata::Metadata
- Inherits:
-
Object
- Object
- PuppetMetadata::Metadata
- Defined in:
- lib/puppet_metadata/metadata.rb
Overview
An abstraction over Puppet metadata
Constant Summary collapse
- SUPPORTED_REQUIREMENTS =
['openvox', 'puppet'].freeze
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.
-
#major_versions(requirement_name) ⇒ Array[Integer]
Supported major Puppet versions.
- #major_versions!(requirement_name) ⇒ Object
-
#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.
-
#requirements ⇒ Hash[String, SemanticPuppet::VersionRange]
A hash representation of the requirements.
- #requirements_with_major_versions ⇒ Object
- #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.
36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet_metadata/metadata.rb', line 36 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 = end |
Instance Attribute Details
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
25 26 27 |
# File 'lib/puppet_metadata/metadata.rb', line 25 def 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.
186 187 188 |
# File 'lib/puppet_metadata/metadata.rb', line 186 def dependencies @dependencies ||= build_version_requirement_hash(['dependencies']) end |
#eol_operatingsystems(at = nil) ⇒ Hash[String, Array[String]]
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/puppet_metadata/metadata.rb', line 99 def (at = nil) at ||= Date.today unsupported = .map do |os, rels| next unless rels eol = rels.select { |rel| .eol?(os, rel, at) } [os, eol] if eol.any? end unsupported.compact.to_h end |
#github_actions(options) ⇒ PuppetMetadata::GithubActions
Returns A GithubActions instance.
199 200 201 |
# File 'lib/puppet_metadata/metadata.rb', line 199 def github_actions() PuppetMetadata::GithubActions.new(self, ) end |
#license ⇒ String
The license
60 61 62 |
# File 'lib/puppet_metadata/metadata.rb', line 60 def license ['license'] end |
#major_versions(requirement_name) ⇒ Array[Integer]
Returns Supported major Puppet versions.
151 152 153 154 155 156 |
# File 'lib/puppet_metadata/metadata.rb', line 151 def major_versions(requirement_name) requirement = requirements[requirement_name] return [] unless requirement major_version_for_requirement(requirement) end |
#major_versions!(requirement_name) ⇒ Object
158 159 160 161 162 163 |
# File 'lib/puppet_metadata/metadata.rb', line 158 def major_versions!(requirement_name) requirement = requirements[requirement_name] raise Exception, "No '#{requirement_name}' requirement found'" unless requirement major_version_for_requirement(requirement) end |
#name ⇒ String
The name
48 49 50 |
# File 'lib/puppet_metadata/metadata.rb', line 48 def name ['name'] end |
#operatingsystems ⇒ Hash[String, Array[String]]
Returns The supported operating system and its major releases.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/puppet_metadata/metadata.rb', line 66 def ||= 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
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/puppet_metadata/metadata.rb', line 85 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 |
#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.
131 132 133 |
# File 'lib/puppet_metadata/metadata.rb', line 131 def requirements @requirements ||= build_version_requirement_hash(['requirements']) end |
#requirements_with_major_versions ⇒ Object
142 143 144 145 146 147 |
# File 'lib/puppet_metadata/metadata.rb', line 142 def requirements_with_major_versions SUPPORTED_REQUIREMENTS.filter_map do |requirement| majors = major_versions(requirement) [requirement, majors] unless majors.empty? end.to_h end |
#satisfies_dependency?(name, version) ⇒ Boolean
193 194 195 |
# File 'lib/puppet_metadata/metadata.rb', line 193 def satisfies_dependency?(name, version) matches?(dependencies[name], version) end |
#satisfies_requirement?(name, version) ⇒ Boolean
138 139 140 |
# File 'lib/puppet_metadata/metadata.rb', line 138 def satisfies_requirement?(name, version) matches?(requirements[name], version) end |
#version ⇒ String
The version
54 55 56 |
# File 'lib/puppet_metadata/metadata.rb', line 54 def version ['version'] end |