Class: Rack::GitSha

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/git_sha.rb,
lib/rack/git_sha/version.rb

Constant Summary collapse

VERSION =
"1.2.0"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = Dir.pwd) ⇒ GitSha

Public: Initialize a new GitSha app.

root - The String path to application root.

Returns the instance of GitSha.



16
17
18
# File 'lib/rack/git_sha.rb', line 16

def initialize(root = Dir.pwd)
  @root = Pathname.new(root)
end

Class Method Details

.call(env) ⇒ Object



7
8
9
# File 'lib/rack/git_sha.rb', line 7

def self.call(env)
  new.call(env)
end

Instance Method Details

#call(env) ⇒ Object

Public: Rack interface, run when the application is requested.

env - The Hash environment of the incoming request.

Returns an Array ‘[status, headers, [body]]` for Rack.



25
26
27
28
29
30
31
32
33
# File 'lib/rack/git_sha.rb', line 25

def call(env)
  if revision_file.exist?
    ok revision_file.read
  elsif git_repository?
    ok git_current_commit_sha
  else
    not_found 'Could not determine SHA'
  end
end