Class: Rapporteur::Revision
- Inherits:
-
Object
- Object
- Rapporteur::Revision
- Defined in:
- lib/rapporteur/revision.rb
Overview
Manages memoizing and maintaining the current application revision.
Class Method Summary collapse
-
.calculate_current(revision = default_revision_source) ⇒ Object
Internal: Calculates the current revision from the configured revision source.
-
.current ⇒ Object
Public: Returns the current revision as a String.
-
.current=(revision) ⇒ Object
Public: Forcibly sets the current application revision.
-
.default_revision_source ⇒ Object
Internal: The default method of determining the current revision.
Class Method Details
.calculate_current(revision = default_revision_source) ⇒ Object
Internal: Calculates the current revision from the configured revision source.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rapporteur/revision.rb', line 43 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 ⇒ Object
Public: Returns the current revision as a String.
9 10 11 |
# File 'lib/rapporteur/revision.rb', line 9 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.
25 26 27 |
# File 'lib/rapporteur/revision.rb', line 25 def self.current=(revision) self._current = calculate_current(revision) end |
.default_revision_source ⇒ Object
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.
35 36 37 38 |
# File 'lib/rapporteur/revision.rb', line 35 def self.default_revision_source `git rev-parse HEAD 2>/dev/null`.strip rescue end |