module Builderator::Control::Version::SCM

Generic SCM interface

Public Class Methods

history() click to toggle source
# File lib/builderator/control/version/scm.rb, line 48
def history
  provider.history
end
provider() click to toggle source

Find a version provider for this build

# File lib/builderator/control/version/scm.rb, line 74
def provider
  providers.find(&:supported?).tap do |found|
    fail 'Builderator::Control::Version: '\
         'Unsupported SCM' if found.nil?
  end
end
providers() click to toggle source
# File lib/builderator/control/version/scm.rb, line 69
def providers
  @providers ||= []
end
register(klass) click to toggle source
# File lib/builderator/control/version/scm.rb, line 56
def register(klass)
  fail 'Provider module must extend '\
       'Builderator::Control::Version::SCM' unless
       klass.singleton_class.include?(SCM)

  ## Make newer providers override those with the same capability
  providers.unshift(klass)
end
tags() click to toggle source
# File lib/builderator/control/version/scm.rb, line 52
def tags
  provider.tags
end
unregister(klass) click to toggle source
# File lib/builderator/control/version/scm.rb, line 65
def unregister(klass)
  providers.delete(klass)
end

Public Instance Methods

_history() click to toggle source

OVERRIDE: Return an array of hashes with keys

  • id -> SCM commit identity

  • message -> SCM commit message

  • tags -> nil or an array of strings

# File lib/builderator/control/version/scm.rb, line 34
def _history
  fail 'Method `_history` must be implemented in SCM providers!'
end
_tags() click to toggle source

OVERRIDE: Return an array of [tag, commit-id] tuples

# File lib/builderator/control/version/scm.rb, line 41
def _tags
  history.reject { |commit| commit.tags.empty? }
    .map { |commit| commit.tags.map { |tag| [tag, commit.id] } }
    .each_with_object([]) { |commit, tags| tags.push(*commit) }
end
history() click to toggle source

Fetch and cache history for the current HEAD/TIP

# File lib/builderator/control/version/scm.rb, line 9
def history
  @history ||= _history.map { |commit| Commit.new(commit) }
end
supported?() click to toggle source

OVERRIDE: Return true if this provider will work for `path`

# File lib/builderator/control/version/scm.rb, line 24
def supported?
  fail 'Method `supported?` must be implemented in SCM providers!'
end
tags() click to toggle source

Find all tags in the branch's history

# File lib/builderator/control/version/scm.rb, line 14
def tags
  @tags ||= _tags
            .map { |tag, ref| Version.from_string(tag, :ref => ref) }
            .compact
            .sort
end