Class: Habitat::PackageIdent
- Inherits:
-
Struct
- Object
- Struct
- Habitat::PackageIdent
- Defined in:
- lib/habitat/client.rb
Overview
Habitat Package Ident
This class builds a Habitat Package Identifier object using the
four components of a Habitat package: origin, package name (pkg),
version, and release. It subclasses Struct with arguments that
have default values - 'latest' for version and release. It
also implements a method to return the package identifier as a /
separated string for use in the Habitat Depot API
rubocop:disable StructInheritance
Instance Attribute Summary collapse
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#pkg ⇒ Object
Returns the value of attribute pkg.
-
#release ⇒ Object
Returns the value of attribute release.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(origin, pkg, version = 'latest', release = 'latest') ⇒ PackageIdent
constructor
Creates the package identifier using the origin and package name.
-
#to_s ⇒ Object
Returns a string from a
Habitat::PackageIdentobject separated by/(forward slash).
Constructor Details
#initialize(origin, pkg, version = 'latest', release = 'latest') ⇒ PackageIdent
Creates the package identifier using the origin and package name. Optionally will also use the version and release, or sets them to latest if not specified.
Attributes
origin- The package originpkg- The package nameversion- The version of the packagerelease- The timestamp release of the package
Examples
Use the latest core/zlib package:
Habitat::PackageIdent.new('core', 'zlib')
Use version 1.2.8 of the core/zlib package:
Habitat::PackageIdent.new('core', 'zlib', '1.2.8')
Use a specific release of version 1.2.8 of the core/zlib package:
Habitat::PackageIdent.new('core', 'zlib', '1.2.8', '20160222155343')
Pass an array as an argument:
Habitat::PackageIdent.new(*['core', 'zlib'])
For example, from a #split string:
Habitat::PackageIdent.new(*'core/zlib'.split('/'))
303 304 305 |
# File 'lib/habitat/client.rb', line 303 def initialize(origin, pkg, version = 'latest', release = 'latest') super end |
Instance Attribute Details
#origin ⇒ Object
Returns the value of attribute origin
268 269 270 |
# File 'lib/habitat/client.rb', line 268 def origin @origin end |
#pkg ⇒ Object
Returns the value of attribute pkg
268 269 270 |
# File 'lib/habitat/client.rb', line 268 def pkg @pkg end |
#release ⇒ Object
Returns the value of attribute release
268 269 270 |
# File 'lib/habitat/client.rb', line 268 def release @release end |
#version ⇒ Object
Returns the value of attribute version
268 269 270 |
# File 'lib/habitat/client.rb', line 268 def version @version end |
Instance Method Details
#to_s ⇒ Object
Returns a string from a Habitat::PackageIdent object separated by
/ (forward slash).
Examples
zlib = Habitat::PackageIdent.new('core', 'zlib')
zlib.to_s #=> "core/zlib/latest"
315 316 317 318 319 320 321 322 |
# File 'lib/habitat/client.rb', line 315 def to_s parts = if self[:version] == 'latest' [self[:origin], self[:pkg], self[:version]] else [self[:origin], self[:pkg], self[:version], self[:release]] end parts.join('/') end |