Class: Puppet::Moddeps::Module
- Inherits:
-
Object
- Object
- Puppet::Moddeps::Module
- Defined in:
- lib/puppet/moddeps/module.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_hash(mod) ⇒ Object
Creates a new module from a hash.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Checks two modules for equality.
-
#hash ⇒ Object
Hashes the module.
-
#initialize(owner, name, version = nil) ⇒ Module
constructor
A new instance of Module.
-
#title ⇒ Object
(also: #to_s)
Returns the module’s title.
-
#to_hash ⇒ Object
Returns a hash representation similar to the module declaration.
-
#to_spec ⇒ Object
Returns the Puppetfile specification for the module.
-
#versions_intersect?(other) ⇒ Boolean
Returns true if the versions of two modules intersect.
Constructor Details
#initialize(owner, name, version = nil) ⇒ Module
Returns a new instance of Module.
11 12 13 14 15 |
# File 'lib/puppet/moddeps/module.rb', line 11 def initialize(owner, name, version = nil) @owner = owner @name = name @version = version unless version == :latest end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/puppet/moddeps/module.rb', line 9 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
9 10 11 |
# File 'lib/puppet/moddeps/module.rb', line 9 def owner @owner end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/puppet/moddeps/module.rb', line 9 def version @version end |
Class Method Details
.from_hash(mod) ⇒ Object
Creates a new module from a hash.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# 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 |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Checks two modules for equality.
42 43 44 45 46 47 |
# 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 |
#hash ⇒ Object
Hashes the module.
62 63 64 |
# File 'lib/puppet/moddeps/module.rb', line 62 def hash [@owner, @name].hash end |
#title ⇒ Object Also known as: to_s
Returns the module’s title.
35 36 37 |
# File 'lib/puppet/moddeps/module.rb', line 35 def title "#{@owner}-#{@name}" end |
#to_hash ⇒ Object
Returns a hash representation similar to the module declaration.
69 70 71 72 73 74 |
# File 'lib/puppet/moddeps/module.rb', line 69 def to_hash { 'name' => title, 'version_requirement' => version }.compact end |
#to_spec ⇒ Object
Returns the Puppetfile specification for the module.
78 79 80 81 82 83 84 |
# 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) ⇒ Boolean
Returns true if the versions of two modules intersect. Used to determine if an installed module satisfies the version requirement of another.
53 54 55 56 57 58 |
# 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 |