Class: Habitat::PackageIdent

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

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 origin

  • pkg - The package name

  • version - The version of the package

  • release - 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

#originObject

Returns the value of attribute origin

Returns:

  • (Object)

    the current value of origin



268
269
270
# File 'lib/habitat/client.rb', line 268

def origin
  @origin
end

#pkgObject

Returns the value of attribute pkg

Returns:

  • (Object)

    the current value of pkg



268
269
270
# File 'lib/habitat/client.rb', line 268

def pkg
  @pkg
end

#releaseObject

Returns the value of attribute release

Returns:

  • (Object)

    the current value of release



268
269
270
# File 'lib/habitat/client.rb', line 268

def release
  @release
end

#versionObject

Returns the value of attribute version

Returns:

  • (Object)

    the current value of version



268
269
270
# File 'lib/habitat/client.rb', line 268

def version
  @version
end

Instance Method Details

#to_sObject

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