Module: QueryTracer::Tracer::Revision

Defined in:
lib/query_tracer/tracer/revision.rb

Class Method Summary collapse

Class Method Details

.currentObject

Detect the current code revision and memoize it for the future.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/query_tracer/tracer/revision.rb', line 6

def self.current
  return nil unless QueryTracer.config.show_revision
  
  begin
    # Do we have the code revision memoized?
    unless defined?(@@current_code_revision)
      @@current_code_revision = if File.exists?("#{QueryTracer.config.root}/REVISION")
        # Capistrano-deployed application, we know where to get current revision
        File.read("#{QueryTracer.config.root}/REVISION").chomp.strip
      else
        # Try to use git
        rev = `git rev-parse HEAD 2>/dev/null`.chomp.strip
        rev.empty? ? nil : rev
      end
    end
  rescue
    nil
  end
  humanized_revision
end

.humanized_revisionObject



27
28
29
30
31
# File 'lib/query_tracer/tracer/revision.rb', line 27

def self.humanized_revision
  if @@current_code_revision
    "Rev[#{@@current_code_revision}]"
  end
end