Module: Builderator::Control::Version::SCM

Included in:
Git
Defined in:
lib/builderator/control/version/scm.rb

Overview

Generic SCM interface

Defined Under Namespace

Classes: Commit

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.historyObject



48
49
50
# File 'lib/builderator/control/version/scm.rb', line 48

def history
  provider.history
end

.providerObject

Find a version provider for this build



74
75
76
77
78
79
# 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

.providersObject



69
70
71
# File 'lib/builderator/control/version/scm.rb', line 69

def providers
  @providers ||= []
end

.register(klass) ⇒ Object



56
57
58
59
60
61
62
63
# 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

.tagsObject



52
53
54
# File 'lib/builderator/control/version/scm.rb', line 52

def tags
  provider.tags
end

.unregister(klass) ⇒ Object



65
66
67
# File 'lib/builderator/control/version/scm.rb', line 65

def unregister(klass)
  providers.delete(klass)
end

Instance Method Details

#_historyObject

OVERRIDE: Return an array of hashes with keys

  • id -> SCM commit identity

  • message -> SCM commit message

  • tags -> nil or an array of strings



34
35
36
# File 'lib/builderator/control/version/scm.rb', line 34

def _history
  fail 'Method `_history` must be implemented in SCM providers!'
end

#_tagsObject

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



41
42
43
44
45
# 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

#historyObject

Fetch and cache history for the current HEAD/TIP



9
10
11
# File 'lib/builderator/control/version/scm.rb', line 9

def history
  @history ||= _history.map { |commit| Commit.new(commit) }
end

#supported?Boolean

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

Returns:

  • (Boolean)


24
25
26
# File 'lib/builderator/control/version/scm.rb', line 24

def supported?
  fail 'Method `supported?` must be implemented in SCM providers!'
end

#tagsObject

Find all tags in the branch’s history



14
15
16
17
18
19
# 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