rack-git_sha 0.0.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,12 +1,16 @@
1
1
  # Rack::GitSha
2
2
 
3
- TODO: Write a gem description
3
+ Tiny rack application that serves up the currently deployed git commit SHA.
4
+
5
+ Inspired by [https://github.com/site/sha](https://github.com/site/sha)
4
6
 
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
8
10
 
9
- gem 'rack-git_sha'
11
+ ```ruby
12
+ gem 'rack-git_sha'
13
+ ```
10
14
 
11
15
  And then execute:
12
16
 
@@ -18,7 +22,51 @@ Or install it yourself as:
18
22
 
19
23
  ## Usage
20
24
 
21
- TODO: Write usage instructions here
25
+ If your using rails 3.0+ you can mount the app in your `routes.rb` file.
26
+
27
+ ```ruby
28
+ MyApp::Application.routes.draw do
29
+ mount Rack::GitSha.new => '/sha'
30
+ end
31
+ ```
32
+
33
+ If your using rack then you can map the middleware in your `config.ru`.
34
+
35
+ ```ruby
36
+ require 'rack/git_sha'
37
+
38
+ map '/sha' do
39
+ run Rack::GitSha.new
40
+ end
41
+
42
+ map '/' do
43
+ run lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['Homepage']] }
44
+ end
45
+ ```
46
+
47
+ The argument that is given to `#new` is the path to the current project,
48
+ it will default to `Dir.pwd` if none is given.
49
+
50
+ After restarting your app, visiting `/sha` should give you the current
51
+ git revision.
52
+
53
+ ## Tips
54
+
55
+ Once you've got your application serving the current SHA you can do some
56
+ fun stuff from the command line.
57
+
58
+ ### Currently deployed SHA
59
+
60
+ cd example-app
61
+ curl -s http://app.example.com/sha
62
+ git diff $(curl -fsSL http://app.example.com/sha)
63
+
64
+ This will do a diff against the deployed sha, showing you what is still
65
+ pending (much like capistrano's `cap deploy:pending:diff`).
66
+
67
+ ## Known issues
68
+
69
+ * Does not work with Heroku.
22
70
 
23
71
  ## Contributing
24
72
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => :spec
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class GitSha
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
data/lib/rack/git_sha.rb CHANGED
@@ -3,10 +3,21 @@ require 'pathname'
3
3
 
4
4
  module Rack
5
5
  class GitSha
6
+
7
+ # Public: Initialize a new GitSha app.
8
+ #
9
+ # root - The String path to application root.
10
+ #
11
+ # Returns the instance of GitSha.
6
12
  def initialize(root = Dir.pwd)
7
13
  @root = Pathname.new(root)
8
14
  end
9
15
 
16
+ # Public: Rack interface, run when the application is requested.
17
+ #
18
+ # env - The Hash environment of the incoming request.
19
+ #
20
+ # Returns an Array `[status, headers, [body]]` for Rack.
10
21
  def call(env)
11
22
  if revision_file.exist?
12
23
  ok revision_file.read
@@ -19,26 +30,49 @@ module Rack
19
30
 
20
31
  private
21
32
 
33
+ # Get a reference to the `REVISION` file in the root of the app, this is
34
+ # for Capistrano compatibility.
35
+ #
36
+ # Returns the Pathname to a possible REVISION file.
22
37
  def revision_file
23
38
  @root.join('REVISION')
24
39
  end
25
40
 
41
+ # Check if the application root is a git repository.
42
+ #
43
+ # Returns a Boolean.
26
44
  def git_repository?
27
45
  @root.join('.git').directory?
28
46
  end
29
47
 
48
+ # Get the current git commit SHA.
49
+ #
50
+ # Returns the String of the SHA.
30
51
  def git_current_commit_sha
31
52
  `git rev-parse HEAD`
32
53
  end
33
54
 
55
+ # Easy way to get a rack 200 OK response.
56
+ #
57
+ # response - The String to return as the body.
58
+ #
59
+ # Returns a Rack compatible response array.
34
60
  def ok(response)
35
61
  [200, headers, [response]]
36
62
  end
37
63
 
64
+ # Easy way to get a rack 404 response.
65
+ #
66
+ # response - The String to return as the body.
67
+ #
68
+ # Returns a Rack compatible response array.
38
69
  def not_found(response)
39
70
  [404, headers, [response]]
40
71
  end
41
72
 
73
+ # Get the headers for the response.
74
+ #
75
+ # Returns a Hash of the response headers.
42
76
  def headers
43
77
  {'Content-Type' => 'text/plain'}
44
78
  end
data/rack-git_sha.gemspec CHANGED
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency 'rspec', '~> 2.8.0'
19
19
  gem.add_development_dependency 'rack-test', '~> 0.6.1'
20
+ gem.add_development_dependency 'rake', '~> 0.9.2'
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-git_sha
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-18 00:00:00.000000000 Z
12
+ date: 2012-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70309363854700 !ruby/object:Gem::Requirement
16
+ requirement: &70263737936820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.8.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70309363854700
24
+ version_requirements: *70263737936820
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &70309363854180 !ruby/object:Gem::Requirement
27
+ requirement: &70263737936300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,18 @@ dependencies:
32
32
  version: 0.6.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70309363854180
35
+ version_requirements: *70263737936300
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70263737935840 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70263737935840
36
47
  description: Serve up the current git commit SHA from rack
37
48
  email:
38
49
  - self@hecticjeff.net