class Puppet::Moddeps::Module
Attributes
name[R]
owner[R]
version[R]
Public Class Methods
from_hash(mod)
click to toggle source
Creates a new module from a hash.
# File lib/puppet/moddeps/module.rb, line 19 def self.from_hash(mod) unless mod['name'].is_a?(String) raise "Module name must be a String, not #{mod['name'].inspect}" end owner, name = mod['name'].tr('/', '-').split('-', 2) unless owner && name raise "Module name #{mod['name']} must include both the owner and module name." end new(owner, name, mod['version_requirement']) end
new(owner, name, version = nil)
click to toggle source
# File lib/puppet/moddeps/module.rb, line 11 def initialize(owner, name, version = nil) @owner = owner @name = name @version = version unless version == :latest end
Public Instance Methods
eql?(other)
click to toggle source
Checks two modules for equality.
# File lib/puppet/moddeps/module.rb, line 42 def eql?(other) self.class == other.class && @owner == other.owner && @name == other.name && versions_intersect?(other) end
Also aliased as: ==
hash()
click to toggle source
Hashes the module.
# File lib/puppet/moddeps/module.rb, line 62 def hash [@owner, @name].hash end
title()
click to toggle source
Returns the module's title.
# File lib/puppet/moddeps/module.rb, line 35 def title "#{@owner}-#{@name}" end
Also aliased as: to_s
to_hash()
click to toggle source
Returns a hash representation similar to the module declaration.
# File lib/puppet/moddeps/module.rb, line 69 def to_hash { 'name' => title, 'version_requirement' => version }.compact end
to_spec()
click to toggle source
Returns the Puppetfile specification for the module.
# File lib/puppet/moddeps/module.rb, line 78 def to_spec if @version "mod #{title.inspect}, #{@version.inspect}" else "mod #{title.inspect}" end end
versions_intersect?(other)
click to toggle source
Returns true if the versions of two modules intersect. Used to determine if an installed module satisfies the version requirement of another.
# File lib/puppet/moddeps/module.rb, line 53 def versions_intersect?(other) range = ::SemanticPuppet::VersionRange.parse(@version || '') other_range = ::SemanticPuppet::VersionRange.parse(other.version || '') range.intersection(other_range) != ::SemanticPuppet::VersionRange::EMPTY_RANGE end