sha_header 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1,52 @@
1
- rvm gemset use sha_header
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p327@sha_header"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.16.20 (version)" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ if [[ $- == *i* ]] # check for interactive shells
29
+ then echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
30
+ else echo "Using: $GEM_HOME" # don't use colors in non-interactive shells
31
+ fi
32
+ else
33
+ # If the environment file has not yet been created, use the RVM CLI to select.
34
+ rvm --create use "$environment_id" || {
35
+ echo "Failed to create RVM environment '${environment_id}'."
36
+ return 1
37
+ }
38
+ fi
39
+
40
+ # If you use bundler, this might be useful to you:
41
+ # if [[ -s Gemfile ]] && {
42
+ # ! builtin command -v bundle >/dev/null ||
43
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
44
+ # }
45
+ # then
46
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
47
+ # gem install bundler
48
+ # fi
49
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
50
+ # then
51
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
52
+ # fi
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # SHAHeader
2
+
3
+ SHAHeader is a simple Rack middleware gem for Rails 3. When required, it
4
+ will instruct Rails to automatically insert its middleware into the Rack
5
+ stack and inject your current git SHA hash into all of your dynamic
6
+ response headers.
7
+
8
+ ## Compatibility
9
+
10
+ The SHAHeader gem is both Ruby 1.8.7 and 1.9.2 compatible. Currently,
11
+ it is compatible with Rails 3.x.
12
+
13
+ ## Installation
14
+
15
+ In Rails 3, modify your `Gemfile` to add the following line:
16
+
17
+ gem 'sha_header'
18
+
19
+ That's it. It is distributed with a `Railtie` to instruct Rails on how
20
+ to set it up, so no other coding is required.
21
+
22
+ ## Example
23
+
24
+ Here's a simple example for a Rails application running locally. The
25
+ application has added the above `Gemfile` line. Using curl:
26
+
27
+ curl -I http://localhost:3000/
28
+
29
+ And, the following response is received:
30
+
31
+ HTTP/1.1 200 OK
32
+ Content-Type: text/html; charset=utf-8
33
+ ETag: "25ec427afba8daa376f309559b1b3c5c"
34
+ Cache-Control: max-age=0, private, must-revalidate
35
+ X-Git-SHA: 8c139c519c731be597d0c37a6e5ce46a27bab174
36
+ X-UA-Compatible: IE=Edge
37
+ X-Runtime: 0.120340
38
+ Content-Length: 0
39
+ Connection: Keep-Alive
40
+
41
+ (Notice the `X-Git-SHA` header)
data/Rakefile CHANGED
@@ -4,6 +4,8 @@ Bundler::GemHelper.install_tasks
4
4
  require 'rake'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
+ task :default => :spec
8
+
7
9
  desc "Run all examples"
8
10
  RSpec::Core::RakeTask.new('spec') do |t|
9
11
  t.pattern = 'spec/**/*_spec.rb'
@@ -1,10 +1,7 @@
1
1
  require 'active_support/core_ext/object/blank'
2
- require 'active_support/memoizable'
3
2
 
4
3
  module SHAHeader
5
4
  class Middleware
6
- extend ::ActiveSupport::Memoizable
7
-
8
5
  def initialize(app, options = {})
9
6
  @app = app
10
7
  end
@@ -28,14 +25,15 @@ module SHAHeader
28
25
  end
29
26
 
30
27
  def current_git_sha
31
- if revision_present?
32
- File.read(::Rails.root.join('REVISION'))
33
- elsif on_heroku?
34
- ENV['COMMIT_HASH']
35
- else
36
- `cd "#{::Rails.root}" && git rev-parse HEAD 2>/dev/null`.strip
28
+ @current_git_sha ||= begin
29
+ if revision_present?
30
+ File.read(::Rails.root.join('REVISION')).strip
31
+ elsif on_heroku?
32
+ ENV['COMMIT_HASH'].strip
33
+ else
34
+ `cd "#{::Rails.root}" && git rev-parse HEAD 2>/dev/null`.strip
35
+ end
37
36
  end
38
37
  end
39
- memoize :current_git_sha
40
38
  end
41
39
  end
@@ -1,3 +1,3 @@
1
1
  module SHAHeader
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/sha_header.gemspec CHANGED
@@ -12,12 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Add a header to the response of your Rails 3 application containing the current commit SHA.}
13
13
  s.description = %q{This library adds a new, custom X-Git-SHA header to your Rails 3 application's response which contains the SHA hash that your application is currently running.}
14
14
 
15
- s.rubyforge_project = 'sha_header'
15
+ s.add_dependency 'railties', '~>3.0'
16
16
 
17
- s.add_dependency 'rails', '~>3.0.0'
18
-
19
- s.add_development_dependency 'rspec', '~>2.5.0'
20
- s.add_development_dependency 'fakefs', '~>0.3.0'
17
+ s.add_development_dependency 'rspec', '~>2.5'
18
+ s.add_development_dependency 'fakefs', '~>0.4'
21
19
 
22
20
  s.files = `git ls-files`.split("\n")
23
21
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,8 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe SHAHeader::Middleware do
4
- include FakeFS::SpecHelpers
5
-
6
4
  let(:parent_app) {lambda { |env| [200, {'Content-Type' => 'text/plain'}, ['Hello']] }}
7
5
  let(:middleware) { SHAHeader::Middleware.new(parent_app) }
8
6
  let(:env) { Rack::MockRequest.env_for('/hello') }
@@ -21,14 +19,14 @@ describe SHAHeader::Middleware do
21
19
  it { should == 'ABCDEFG' }
22
20
  end
23
21
 
24
- context 'with a REVISION file' do
25
- use_fakefs
26
-
27
- let(:path) { Rails.root.join('REVISION') }
28
- before(:each) { File.open(path, 'w') { |file| file.write 'HIJKLMNO' }}
29
- after(:each) { File.delete(path) }
22
+ context 'with a REVISION file', :fakefs do
23
+ use_fakefs(self) do
24
+ let(:path) { Rails.root.join('REVISION') }
25
+ before(:each) { File.open(path, 'w') { |file| file.write 'HIJKLMNO' }}
26
+ after(:each) { File.delete(path) }
30
27
 
31
- it { should == 'HIJKLMNO' }
28
+ it { should == 'HIJKLMNO' }
29
+ end
32
30
  end
33
31
 
34
32
  context 'when querying git' do
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,15 @@
1
- $:.unshift(File.expand_path('../', __FILE__))
2
- $:.unshift(File.expand_path('../../lib', __FILE__))
3
-
4
- require 'rspec'
5
- require 'rack'
6
1
  require 'sha_header'
7
2
 
8
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |support|
9
- require support
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+
8
+ # Run specs in random order to surface order dependencies. If you find an
9
+ # order dependency and want to debug it, you can fix the order by providing
10
+ # the seed, which is printed after each run.
11
+ # --seed 1234
12
+ config.order = 'random'
10
13
  end
11
14
 
15
+ Dir[File.expand_path("../support/*.rb", __FILE__)].each { |f| require f }
@@ -1,18 +1,5 @@
1
- require 'fakefs'
2
-
3
- module FakeFS::SpecHelpers
4
- def use_fakefs
5
- before(:each) do
6
- FakeFS.activate!
7
- end
8
-
9
- after(:each) do
10
- FakeFS.deactivate!
11
- FakeFS::FileSystem.clear
12
- end
13
- end
14
- end
1
+ require 'fakefs/spec_helpers'
15
2
 
16
3
  RSpec.configure do |config|
17
- config.extend FakeFS::SpecHelpers
4
+ config.include FakeFS::SpecHelpers, :fakefs
18
5
  end
@@ -0,0 +1 @@
1
+ require 'rack'
metadata CHANGED
@@ -1,84 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sha_header
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Nathaniel Bibler
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-03-31 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: rails
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2012-11-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 3
32
- - 0
33
- - 0
34
- version: 3.0.0
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
34
+ requirements:
43
35
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 27
46
- segments:
47
- - 2
48
- - 5
49
- - 0
50
- version: 2.5.0
36
+ - !ruby/object:Gem::Version
37
+ version: '2.5'
51
38
  type: :development
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: fakefs
55
39
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
42
+ requirements:
59
43
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 19
62
- segments:
63
- - 0
64
- - 3
65
- - 0
66
- version: 0.3.0
44
+ - !ruby/object:Gem::Version
45
+ version: '2.5'
46
+ - !ruby/object:Gem::Dependency
47
+ name: fakefs
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.4'
67
54
  type: :development
68
- version_requirements: *id003
69
- description: This library adds a new, custom X-Git-SHA header to your Rails 3 application's response which contains the SHA hash that your application is currently running.
70
- email:
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ description: This library adds a new, custom X-Git-SHA header to your Rails 3 application's
63
+ response which contains the SHA hash that your application is currently running.
64
+ email:
71
65
  - gem@nathanielbibler.com
72
66
  executables: []
73
-
74
67
  extensions: []
75
-
76
68
  extra_rdoc_files: []
77
-
78
- files:
69
+ files:
79
70
  - .gitignore
80
71
  - .rvmrc
81
72
  - Gemfile
73
+ - README.md
82
74
  - Rakefile
83
75
  - lib/sha_header.rb
84
76
  - lib/sha_header/middleware.rb
@@ -88,43 +80,36 @@ files:
88
80
  - spec/models/middleware_spec.rb
89
81
  - spec/spec_helper.rb
90
82
  - spec/support/fakefs.rb
83
+ - spec/support/rack.rb
91
84
  - spec/support/rails.rb
92
- has_rdoc: true
93
85
  homepage: https://github.com/nbibler/sha_header
94
86
  licenses: []
95
-
96
87
  post_install_message:
97
88
  rdoc_options: []
98
-
99
- require_paths:
89
+ require_paths:
100
90
  - lib
101
- required_ruby_version: !ruby/object:Gem::Requirement
91
+ required_ruby_version: !ruby/object:Gem::Requirement
102
92
  none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
108
- - 0
109
- version: "0"
110
- required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
98
  none: false
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- hash: 3
116
- segments:
117
- - 0
118
- version: "0"
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
119
103
  requirements: []
120
-
121
- rubyforge_project: sha_header
122
- rubygems_version: 1.6.2
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.24
123
106
  signing_key:
124
107
  specification_version: 3
125
- summary: Add a header to the response of your Rails 3 application containing the current commit SHA.
126
- test_files:
108
+ summary: Add a header to the response of your Rails 3 application containing the current
109
+ commit SHA.
110
+ test_files:
127
111
  - spec/models/middleware_spec.rb
128
112
  - spec/spec_helper.rb
129
113
  - spec/support/fakefs.rb
114
+ - spec/support/rack.rb
130
115
  - spec/support/rails.rb