sasha 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -9,12 +9,29 @@ git? rails?
9
9
 
10
10
  ## Usage
11
11
 
12
- ### Rails 3 or Rails 2 with Bundler
12
+ ### Rails 3
13
13
 
14
14
  Add it to your Gemfile, you are using bundler, right?
15
15
 
16
16
  gem 'sasha'
17
17
 
18
+ ### Rails 2
19
+
20
+ Install the gem:
21
+
22
+ gem install sasha
23
+
24
+ Add to bottom of environment.rb:
25
+
26
+ require 'sasha'
27
+
28
+ ### Sinatra
29
+
30
+ Require it on *config.ru* after sinatra/base
31
+
32
+ require 'sinatra/base'
33
+ require 'sasha'
34
+
18
35
  ## Test it
19
36
 
20
37
  $ curl -I http://www.example.net | grep X-Git-SHA
data/lib/sasha/git.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Sasha
2
+ class Git
3
+ def self.current_sha
4
+ @current_sha ||= `git rev-parse HEAD`.chomp
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module ActionController
2
+ class Base
3
+ before_filter :set_git_sha_header
4
+
5
+ def set_git_sha_header
6
+ warn "No git found for current project" unless Sasha::Git.current_sha
7
+ headers['X-Git-SHA'] = Sasha::Git.current_sha
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Sinatra
2
+ class Base
3
+ before do
4
+ headers "X-Git-SHA" => Sasha::Git.current_sha
5
+ end
6
+ end
7
+ end
data/lib/sasha/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sasha
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/sasha.rb CHANGED
@@ -1,17 +1,6 @@
1
- require 'action_controller'
2
-
3
1
  module Sasha
4
- class Git
5
- def self.current_sha
6
- @current_sha ||= `git rev-parse HEAD`.chomp
7
- end
8
- end
2
+ autoload :Git, 'sasha/git'
9
3
  end
10
4
 
11
- class ActionController::Base
12
- before_filter :set_git_sha_header
13
-
14
- def set_git_sha_header
15
- headers['X-Git-SHA'] = Sasha::Git.current_sha
16
- end
17
- end
5
+ require 'sasha/rails' if defined?(ActionController)
6
+ require 'sasha/sinatra' if defined?(Sinatra)
@@ -6,8 +6,15 @@ class TestController < ActionController::TestCase
6
6
  end
7
7
 
8
8
  def test_header_included_in_request
9
- Sasha::Git.expects(:current_sha).returns('ABC123ABC123')
9
+ Sasha::Git.expects(:current_sha).twice.returns('ABC123ABC123')
10
10
  get 'index'
11
11
  assert_equal 'ABC123ABC123', response.headers['X-Git-SHA']
12
12
  end
13
+
14
+ def test_warning
15
+ Sasha::Git.expects(:current_sha).twice.returns(nil)
16
+ @controller.expects(:warn).once.with(instance_of(String))
17
+ get 'index'
18
+ assert_equal nil, response.headers['X-Git-SHA']
19
+ end
13
20
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sasha
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David Padilla
@@ -75,6 +75,9 @@ files:
75
75
  - README.md
76
76
  - Rakefile
77
77
  - lib/sasha.rb
78
+ - lib/sasha/git.rb
79
+ - lib/sasha/rails.rb
80
+ - lib/sasha/sinatra.rb
78
81
  - lib/sasha/version.rb
79
82
  - sasha.gemspec
80
83
  - test/test_helper.rb