Class: Bolt::Puppetfile::Module
- Inherits:
-
Object
- Object
- Bolt::Puppetfile::Module
- Defined in:
- lib/bolt/puppetfile/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
Returns the module’s title.
-
#to_spec ⇒ Object
Returns the Puppetfile specification for the module.
Constructor Details
#initialize(owner, name, version = nil) ⇒ Module
Returns a new instance of Module.
13 14 15 16 17 |
# File 'lib/bolt/puppetfile/module.rb', line 13 def initialize(owner, name, version = nil) @owner = owner @name = name @version = version end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/bolt/puppetfile/module.rb', line 11 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
11 12 13 |
# File 'lib/bolt/puppetfile/module.rb', line 11 def owner @owner end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
11 12 13 |
# File 'lib/bolt/puppetfile/module.rb', line 11 def version @version end |
Class Method Details
.from_hash(mod) ⇒ Object
Creates a new module from a hash.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bolt/puppetfile/module.rb', line 21 def self.from_hash(mod) unless mod['name'].is_a?(String) raise Bolt::ValidationError, "Module name must be a String, not #{mod['name'].inspect}" end owner, name = mod['name'].tr('/', '-').split('-', 2) unless owner && name raise Bolt::ValidationError, "Module name #{mod['name']} must include both the owner and module name." end new(owner, name) end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Checks two modules for equality.
44 45 46 |
# File 'lib/bolt/puppetfile/module.rb', line 44 def eql?(other) self.class == other.class && @owner == other.owner && @name == other.name end |
#hash ⇒ Object
Hashes the module.
51 52 53 |
# File 'lib/bolt/puppetfile/module.rb', line 51 def hash [@owner, @name].hash end |
#title ⇒ Object
Returns the module’s title.
38 39 40 |
# File 'lib/bolt/puppetfile/module.rb', line 38 def title "#{@owner}-#{@name}" end |
#to_spec ⇒ Object
Returns the Puppetfile specification for the module.
57 58 59 60 61 62 63 |
# File 'lib/bolt/puppetfile/module.rb', line 57 def to_spec if @version "mod #{title.inspect}, #{@version.inspect}" else "mod #{title.inspect}" end end |