class Rapporteur::Revision

Manages memoizing and maintaining the current application revision.

Public Class Methods

calculate_current(revision = default_revision_source) click to toggle source

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

# 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
current() click to toggle source

Public: Returns the current revision as a String.

# File lib/rapporteur/revision.rb, line 11
def self.current
  self._current ||= calculate_current
end
current=(revision) click to toggle source

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.

# File lib/rapporteur/revision.rb, line 27
def self.current=(revision)
  self._current = calculate_current(revision)
end
default_revision_source() click to toggle source

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.

# File lib/rapporteur/revision.rb, line 37
def self.default_revision_source
  `git rev-parse HEAD 2>/dev/null`.strip
rescue StandardError
end