Sha256: 6e4f5508a3f4ed6c8bdbacd74ac75d38a35d4b8786c12c6fe39955a7c3c902c6

Contents?: true

Size: 1.48 KB

Versions: 8

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require_relative '../../puppet/module_tool'
require_relative '../../puppet/network/format_support'

module Puppet::ModuleTool
  class Dependency
    include Puppet::Network::FormatSupport

    attr_reader :full_module_name, :username, :name, :version_requirement, :repository

    # Instantiates a new module dependency with a +full_module_name+ (e.g.
    # "myuser-mymodule"), and optional +version_requirement+ (e.g. "0.0.1") and
    # optional repository (a URL string).
    def initialize(full_module_name, version_requirement = nil, repository = nil)
      @full_module_name = full_module_name
      # TODO: add error checking, the next line raises ArgumentError when +full_module_name+ is invalid
      @username, @name = Puppet::ModuleTool.username_and_modname_from(full_module_name)
      @version_requirement = version_requirement
      @repository = repository ? Puppet::Forge::Repository.new(repository, nil) : nil
    end

    # We override Object's ==, eql, and hash so we can more easily find identical
    # dependencies.
    def ==(o)
      self.hash == o.hash
    end

    alias :eql? :==

    def hash
      [@full_module_name, @version_requirement, @repository].hash
    end

    def to_data_hash
      result = { :name => @full_module_name }
      result[:version_requirement] = @version_requirement if @version_requirement && !@version_requirement.nil?
      result[:repository] = @repository.to_s if @repository && !@repository.nil?
      result
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-8.5.1 lib/puppet/module_tool/dependency.rb
puppet-8.5.1-x86-mingw32 lib/puppet/module_tool/dependency.rb
puppet-8.5.1-x64-mingw32 lib/puppet/module_tool/dependency.rb
puppet-8.5.1-universal-darwin lib/puppet/module_tool/dependency.rb
puppet-8.5.0 lib/puppet/module_tool/dependency.rb
puppet-8.5.0-x86-mingw32 lib/puppet/module_tool/dependency.rb
puppet-8.5.0-x64-mingw32 lib/puppet/module_tool/dependency.rb
puppet-8.5.0-universal-darwin lib/puppet/module_tool/dependency.rb