Class: BuildpackSupport::BuildpackVersion
- Inherits:
-
Object
- Object
- BuildpackSupport::BuildpackVersion
- Extended by:
- DirectoryFinder
- Defined in:
- lib/buildpack_support/buildpack_version.rb
Overview
A representation of the buildpack’s version. The buildpack’s version is determined using the following algorithm:
-
using the
config/version.yml
file if it exists -
using
git
to determine the remote and hash if the buildpack is in a git repository -
unknown
Instance Attribute Summary collapse
-
#offline ⇒ Boolean
readonly
true
if the buildpack is offline,false
otherwise. -
#version ⇒ String?
readonly
The version name of this version, or
nil
if it cannot be determined.
Instance Method Summary collapse
-
#initialize(should_log = true) ⇒ BuildpackVersion
constructor
Creates a new instance.
-
#to_hash ⇒ Hash
Returns a
Hash
representation of the buildpack version. -
#to_s(human_readable = true) ⇒ String
Creates a string representation of the version.
Methods included from DirectoryFinder
Constructor Details
#initialize(should_log = true) ⇒ BuildpackVersion
Creates a new instance
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/buildpack_support/buildpack_version.rb', line 48 def initialize(should_log = true) configuration = ConfigurationUtils.new(should_log).load 'version' @hash = configuration['hash'] || hash @offline = configuration['offline'] || ENV['OFFLINE'].to_b @remote = configuration['remote'] || remote @version = configuration['version'] || ENV['VERSION'] || @hash return unless should_log logger = Logging::LoggerFactory.instance.get_logger BuildpackVersion logger.debug { to_s } end |
Instance Attribute Details
#offline ⇒ Boolean (readonly)
Returns true
if the buildpack is offline, false
otherwise.
37 38 39 |
# File 'lib/buildpack_support/buildpack_version.rb', line 37 def offline @offline end |
#version ⇒ String? (readonly)
Returns the version name of this version, or nil
if it cannot be determined.
45 46 47 |
# File 'lib/buildpack_support/buildpack_version.rb', line 45 def version @version end |
Instance Method Details
#to_hash ⇒ Hash
Returns a Hash
representation of the buildpack version.
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/buildpack_support/buildpack_version.rb', line 64 def to_hash h = {} h['hash'] = @hash if @hash h['offline'] = @offline if @offline h['remote'] = @remote if @remote h['version'] = @version if @version h end |
#to_s(human_readable = true) ⇒ String
Creates a string representation of the version. The string representation looks like the following: [[<VERSION> [(offline)] | ] <REMOTE>#<HASH>] | [unknown]. Some examples:
2.1.2 (offline) | github.com/cloudfoundry/java-buildpack.git#12345 (custom version number, offline buildpack) abcde | github.com/cloudfoundry/java-buildpack.git#abcde (default version number, online buildpack) github.com/cloudfoundry/java-buildpack#12345 (cloned buildpack) unknown
(un-packaged, un-cloned)
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/buildpack_support/buildpack_version.rb', line 85 def to_s(human_readable = true) s = [] s << @version if @version s << (human_readable ? '(offline)' : 'offline') if @offline s << '|' if @version && human_readable s << "#{@remote}##{@hash}" if @remote && @hash s << 'unknown' if s.empty? s.join(human_readable ? ' ' : '-') end |