lib/bolt/puppetfile/module.rb in bolt-2.28.0 vs lib/bolt/puppetfile/module.rb in bolt-2.29.0
- old
+ new
@@ -28,11 +28,11 @@
unless owner && name
raise Bolt::ValidationError, "Module name #{mod['name']} must include both the owner and module name."
end
- new(owner, name)
+ new(owner, name, mod['version_requirement'])
end
# Returns the module's title.
#
def title
@@ -40,17 +40,40 @@
end
# Checks two modules for equality.
#
def eql?(other)
- self.class == other.class && @owner == other.owner && @name == other.name
+ self.class == other.class &&
+ @owner == other.owner &&
+ @name == other.name &&
+ versions_intersect?(other)
end
alias == eql?
+ # Returns true if the versions of two modules intersect. Used to determine
+ # if an installed module satisfies the version requirement of another.
+ #
+ 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
+
# Hashes the module.
#
def hash
[@owner, @name].hash
+ end
+
+ # Returns a hash representation similar to the module
+ # declaration.
+ #
+ def to_hash
+ {
+ 'name' => title,
+ 'version_requirement' => version
+ }.compact
end
# Returns the Puppetfile specification for the module.
#
def to_spec