rack-revision 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/Gemfile +7 -0
- data/README.md +50 -0
- data/Rakefile +9 -0
- data/lib/rack/revision/version.rb +5 -0
- data/lib/rack/revision.rb +39 -0
- data/rack-revision.gemspec +18 -0
- data/test/test_revision.rb +81 -0
- metadata +73 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
*.swp
|
4
|
+
*.tmproj
|
5
|
+
*~
|
6
|
+
.DS_Store
|
7
|
+
.\#*
|
8
|
+
.bundle
|
9
|
+
.config
|
10
|
+
.yardoc
|
11
|
+
Gemfile.lock
|
12
|
+
InstalledFiles
|
13
|
+
\#*
|
14
|
+
_yardoc
|
15
|
+
coverage
|
16
|
+
doc/
|
17
|
+
lib/bundler/man
|
18
|
+
pkg
|
19
|
+
rdoc
|
20
|
+
spec/reports
|
21
|
+
test/tmp
|
22
|
+
test/version_tmp
|
23
|
+
tmp
|
24
|
+
tmtags
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Rack::Revision
|
2
|
+
|
3
|
+
Rack::Revision is a quick drop-in component to enable code revision tracking.
|
4
|
+
It adds `X-Revision` header with the code revision from capistrano's REVISION file.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
From rubygems:
|
9
|
+
|
10
|
+
```
|
11
|
+
gem install rack-revision
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
Rack::Revision is implemented as a piece of Rack middleware and can be used with
|
17
|
+
any Rack-based application. If you have a `configu.ru` rackup file you can
|
18
|
+
drop the following:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
require 'rack/revision'
|
22
|
+
|
23
|
+
use Rack::Revision
|
24
|
+
|
25
|
+
run YourApp
|
26
|
+
```
|
27
|
+
|
28
|
+
Configuration options:
|
29
|
+
|
30
|
+
- `:header` - Set a custom revision header. Default: `X-Revision`
|
31
|
+
- `:filename` - Set a filename with revision data. Default: `REVISION`
|
32
|
+
- `:default` - Override default `UNDEFINED` revision value
|
33
|
+
|
34
|
+
## Test
|
35
|
+
|
36
|
+
Execute test suite:
|
37
|
+
|
38
|
+
```
|
39
|
+
rake test
|
40
|
+
```
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
Copyright (c) 2012 Dan Sosedoff.
|
45
|
+
|
46
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
49
|
+
|
50
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
class Revision
|
5
|
+
File = ::File
|
6
|
+
@@revision = nil
|
7
|
+
|
8
|
+
def initialize(app, options={})
|
9
|
+
@options = {
|
10
|
+
:header => options[:header] || 'X-Revision',
|
11
|
+
:filename => options[:filename] || 'REVISION',
|
12
|
+
:default => options[:default] || 'UNDEFINED'
|
13
|
+
}
|
14
|
+
|
15
|
+
@app = app
|
16
|
+
@file = File.join(Dir.pwd, @options[:filename])
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
status, headers, body = @app.call(env)
|
21
|
+
headers[@options[:header]] = revision
|
22
|
+
[status, headers, body]
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset_revision
|
26
|
+
@@revision = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def revision
|
32
|
+
@@revision ||= read_revision
|
33
|
+
end
|
34
|
+
|
35
|
+
def read_revision
|
36
|
+
File.exists?(@file) ? File.read(@file).strip : @options[:default]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../lib/rack/revision/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "rack-revision"
|
5
|
+
s.version = Rack::Revision::VERSION
|
6
|
+
s.summary = "Code ravision rack middleware"
|
7
|
+
s.description = "Adds an extra X-REVISION header with source code revision string (git, svn, etc)"
|
8
|
+
s.homepage = "http://github.com/sosedoff/rack-revision"
|
9
|
+
s.authors = ["Dan Sosedoff"]
|
10
|
+
s.email = ["dan.sosedoff@gmail.com"]
|
11
|
+
|
12
|
+
s.add_runtime_dependency 'rack', '>= 1.0'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rack/test'
|
3
|
+
require 'rack/revision'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
class TestRevision < Test::Unit::TestCase
|
7
|
+
include Rack::Test::Methods
|
8
|
+
|
9
|
+
def default_app
|
10
|
+
lambda do |env|
|
11
|
+
headers = {'Content-Type' => "text/html"}
|
12
|
+
[200, headers, ["OK"]]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def app
|
17
|
+
@app ||= Rack::Revision.new(default_app)
|
18
|
+
end
|
19
|
+
|
20
|
+
def app_url
|
21
|
+
"http://foobar.com/"
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_writer :app
|
25
|
+
|
26
|
+
def setup
|
27
|
+
FileUtils.mkdir('./test/tmp')
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
FileUtils.rm_rf('./test/tmp')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_revision_request
|
35
|
+
self.app.reset_revision
|
36
|
+
get app_url
|
37
|
+
|
38
|
+
assert last_response.ok?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_presence
|
42
|
+
self.app.reset_revision
|
43
|
+
get app_url
|
44
|
+
|
45
|
+
assert_not_nil last_response.headers['X-REVISION']
|
46
|
+
assert_not_nil last_response.headers['X-Revision']
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_default_value
|
50
|
+
self.app.reset_revision
|
51
|
+
get app_url
|
52
|
+
|
53
|
+
assert_equal "UNDEFINED", last_response.headers['X-Revision']
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_custom_value
|
57
|
+
self.app = Rack::Revision.new(default_app, :default => "FOOBAR")
|
58
|
+
self.app.reset_revision
|
59
|
+
|
60
|
+
get app_url
|
61
|
+
assert_equal "FOOBAR", last_response.headers['X-Revision']
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_custom_header
|
65
|
+
self.app = Rack::Revision.new(default_app, :header => "FOOBAR")
|
66
|
+
self.app.reset_revision
|
67
|
+
|
68
|
+
get app_url
|
69
|
+
assert_not_nil last_response.headers['FOOBAR']
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_default_filename
|
73
|
+
File.open('./test/tmp/REVISION', 'w') { |f| f.write('qwe123') }
|
74
|
+
|
75
|
+
self.app = Rack::Revision.new(default_app, :filename => './test/tmp/REVISION')
|
76
|
+
self.app.reset_revision
|
77
|
+
|
78
|
+
get app_url
|
79
|
+
assert_equal 'qwe123', last_response.headers['X-Revision']
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-revision
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 1.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dan Sosedoff
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2012-11-26 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description: Adds an extra X-REVISION header with source code revision string (git, svn, etc)
|
27
|
+
email:
|
28
|
+
- dan.sosedoff@gmail.com
|
29
|
+
executables: []
|
30
|
+
|
31
|
+
extensions: []
|
32
|
+
|
33
|
+
extra_rdoc_files: []
|
34
|
+
|
35
|
+
files:
|
36
|
+
- .gitignore
|
37
|
+
- Gemfile
|
38
|
+
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lib/rack/revision.rb
|
41
|
+
- lib/rack/revision/version.rb
|
42
|
+
- rack-revision.gemspec
|
43
|
+
- test/test_revision.rb
|
44
|
+
homepage: http://github.com/sosedoff/rack-revision
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
requirements: []
|
65
|
+
|
66
|
+
rubyforge_project:
|
67
|
+
rubygems_version: 1.8.24
|
68
|
+
signing_key:
|
69
|
+
specification_version: 3
|
70
|
+
summary: Code ravision rack middleware
|
71
|
+
test_files:
|
72
|
+
- test/test_revision.rb
|
73
|
+
has_rdoc:
|