Class: Rapporteur::Revision

Inherits:
Object
  • Object
show all
Defined in:
lib/rapporteur/revision.rb

Overview

Manages memoizing and maintaining the current application revision.

Class Method Summary collapse

Class Method Details

.calculate_current(revision = default_revision_source) ⇒ Object

Internal: Calculates the current revision from the configured revision source.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rapporteur/revision.rb', line 45

def self.calculate_current(revision = default_revision_source)
  case revision
  when String
    revision
  when Proc
    revision.call.to_s
  when NilClass
    'You must provide a Rapporteur::Revision.current= String or Proc'
  else
    raise ArgumentError, "Unknown revision type given: #{revision.inspect}"
  end
end

.currentObject

Public: Returns the current revision as a String.



11
12
13
# File 'lib/rapporteur/revision.rb', line 11

def self.current
  self._current ||= calculate_current
end

.current=(revision) ⇒ Object

Public: Forcibly sets the current application revision.

revision - Either a String or a callable object (Proc, for example) to

use your own environment logic to determine the revision.

Examples

Rapporteur::Revision.current = ENV['REVISION'].strip
Rapporteur::Revision.current = Rails.root.join("REVISION").read.strip

Returns the revision given.



27
28
29
# File 'lib/rapporteur/revision.rb', line 27

def self.current=(revision)
  self._current = calculate_current(revision)
end

.default_revision_sourceObject

Internal: The default method of determining the current revision. This assumes a git executable is in the current PATH and that the process context is running the the appropriate git application directory.

Returns a String containing the current git revision, hopefully.



37
38
39
40
# File 'lib/rapporteur/revision.rb', line 37

def self.default_revision_source
  `git rev-parse HEAD 2>/dev/null`.strip
rescue StandardError
end