rack-revision 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
data/README.md CHANGED
@@ -11,25 +11,41 @@ From rubygems:
11
11
  gem install rack-revision
12
12
  ```
13
13
 
14
+ Or install with bundler:
15
+
16
+ ```
17
+ gem 'rack-revision'
18
+ ```
19
+
20
+ And run `bundle install`
21
+
14
22
  ## Usage
15
23
 
16
24
  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:
25
+ any Rack-based application. If you have a `config.ru` rackup file you can
26
+ drop the following snippet (for sinatra app):
19
27
 
20
28
  ```ruby
21
29
  require 'rack/revision'
22
30
 
31
+ # Basic example
23
32
  use Rack::Revision
24
33
 
25
- run YourApp
34
+ # With custom revision header
35
+ use Rack::Revision, :header => 'X-CODE-VERSION'
36
+
37
+ # With custom filename and default value
38
+ use Rack::Revision, :filename => '.version', :default => 'n/a'
39
+
40
+ run Sinatra::Application
26
41
  ```
27
42
 
28
- Configuration options:
43
+ Available options:
29
44
 
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
45
+ - `:header` - Sets a custom revision header. Default: `X-Revision`
46
+ - `:filename` - Sets a filename with revision data. Default: `REVISION`
47
+ - `:default` - Sets a revision value if file does not exist. Default: UNDEFINED
48
+ - `:rack_env` - Sets a revision value to Rack's `env` hash. Default: `env['rack.app_revision']`
33
49
 
34
50
  ## Test
35
51
 
@@ -47,4 +63,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
47
63
 
48
64
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
65
 
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.
66
+ 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/lib/rack/revision.rb CHANGED
@@ -7,18 +7,19 @@ module Rack
7
7
 
8
8
  def initialize(app, options={})
9
9
  @options = {
10
- :header => options[:header] || 'X-Revision',
10
+ :header => options[:header].nil? ? 'X-Revision' : options[:header],
11
11
  :filename => options[:filename] || 'REVISION',
12
- :default => options[:default] || 'UNDEFINED'
12
+ :default => options[:default] || 'UNDEFINED',
13
+ :rack_env => options[:rack_env].nil? ? 'rack.app_revision' : options[:rack_env]
13
14
  }
14
15
 
15
16
  @app = app
16
- @file = File.join(Dir.pwd, @options[:filename])
17
17
  end
18
18
 
19
19
  def call(env)
20
+ env[@options[:rack_env]] = revision if @options[:rack_env]
20
21
  status, headers, body = @app.call(env)
21
- headers[@options[:header]] = revision
22
+ headers[@options[:header]] = revision if @options[:header]
22
23
  [status, headers, body]
23
24
  end
24
25
 
@@ -33,7 +34,11 @@ module Rack
33
34
  end
34
35
 
35
36
  def read_revision
36
- File.exists?(@file) ? File.read(@file).strip : @options[:default]
37
+ File.exists?(detected_filename) ? File.read(detected_filename).strip : @options[:default]
38
+ end
39
+
40
+ def detected_filename
41
+ @file ||= (@options[:filename] =~ /\A\// ? @options[:filename] : File.join(Dir.pwd, @options[:filename]))
37
42
  end
38
43
  end
39
- end
44
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Revision
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
5
5
  end
@@ -8,9 +8,10 @@ Gem::Specification.new do |s|
8
8
  s.homepage = "http://github.com/sosedoff/rack-revision"
9
9
  s.authors = ["Dan Sosedoff"]
10
10
  s.email = ["dan.sosedoff@gmail.com"]
11
-
11
+
12
12
  s.add_runtime_dependency 'rack', '>= 1.0'
13
-
13
+ s.add_development_dependency 'rack-test', '>= 0'
14
+
14
15
  s.files = `git ls-files`.split("\n")
15
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
@@ -46,6 +46,15 @@ class TestRevision < Test::Unit::TestCase
46
46
  assert_not_nil last_response.headers['X-Revision']
47
47
  end
48
48
 
49
+ def test_blank
50
+ self.app = Rack::Revision.new(default_app, :header => false)
51
+ self.app.reset_revision
52
+ get app_url
53
+
54
+ assert_nil last_response.headers['X-REVISION']
55
+ assert_nil last_response.headers['X-Revision']
56
+ end
57
+
49
58
  def test_default_value
50
59
  self.app.reset_revision
51
60
  get app_url
@@ -69,7 +78,7 @@ class TestRevision < Test::Unit::TestCase
69
78
  assert_not_nil last_response.headers['FOOBAR']
70
79
  end
71
80
 
72
- def test_default_filename
81
+ def test_custom_filename
73
82
  File.open('./test/tmp/REVISION', 'w') { |f| f.write('qwe123') }
74
83
 
75
84
  self.app = Rack::Revision.new(default_app, :filename => './test/tmp/REVISION')
@@ -78,4 +87,39 @@ class TestRevision < Test::Unit::TestCase
78
87
  get app_url
79
88
  assert_equal 'qwe123', last_response.headers['X-Revision']
80
89
  end
81
- end
90
+
91
+ def test_custom_filename_starting_from_root
92
+ File.open('./test/tmp/REVISION', 'w') { |f| f.write('qwe123') }
93
+ filename = File.expand_path("./test/tmp/REVISION")
94
+
95
+ self.app = Rack::Revision.new(default_app, :filename => filename)
96
+ self.app.reset_revision
97
+
98
+ get app_url
99
+ assert_equal 'qwe123', last_response.headers['X-Revision']
100
+ end
101
+
102
+ def test_env_is_present
103
+ self.app.reset_revision
104
+ get app_url
105
+
106
+ assert_not_nil last_request.env['rack.app_revision']
107
+ end
108
+
109
+ def test_custom_env
110
+ self.app = Rack::Revision.new(default_app, :rack_env => 'rack.custom_env')
111
+ self.app.reset_revision
112
+ get app_url
113
+
114
+ assert_nil last_request.env['rack.app_revision']
115
+ assert_not_nil last_request.env['rack.custom_env']
116
+ end
117
+
118
+ def test_disable_env
119
+ self.app = Rack::Revision.new(default_app, :rack_env => false)
120
+ self.app.reset_revision
121
+ get app_url
122
+
123
+ assert_nil last_request.env['rack.app_revision']
124
+ end
125
+ end
metadata CHANGED
@@ -1,39 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-revision
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
4
5
  prerelease:
5
- version: 1.0.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Dan Sosedoff
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-11-26 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-12-17 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: rack
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2157761320 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "1.0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- description: Adds an extra X-REVISION header with source code revision string (git, svn, etc)
27
- email:
23
+ prerelease: false
24
+ version_requirements: *2157761320
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack-test
27
+ requirement: &2157759940 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2157759940
36
+ description: Adds an extra X-REVISION header with source code revision string (git,
37
+ svn, etc)
38
+ email:
28
39
  - dan.sosedoff@gmail.com
29
40
  executables: []
30
-
31
41
  extensions: []
32
-
33
42
  extra_rdoc_files: []
34
-
35
- files:
43
+ files:
36
44
  - .gitignore
45
+ - .travis.yml
37
46
  - Gemfile
38
47
  - README.md
39
48
  - Rakefile
@@ -43,31 +52,28 @@ files:
43
52
  - test/test_revision.rb
44
53
  homepage: http://github.com/sosedoff/rack-revision
45
54
  licenses: []
46
-
47
55
  post_install_message:
48
56
  rdoc_options: []
49
-
50
- require_paths:
57
+ require_paths:
51
58
  - lib
52
- required_ruby_version: !ruby/object:Gem::Requirement
59
+ required_ruby_version: !ruby/object:Gem::Requirement
53
60
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
58
- required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
66
  none: false
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: "0"
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
64
71
  requirements: []
65
-
66
72
  rubyforge_project:
67
- rubygems_version: 1.8.24
73
+ rubygems_version: 1.8.15
68
74
  signing_key:
69
75
  specification_version: 3
70
76
  summary: Code ravision rack middleware
71
- test_files:
77
+ test_files:
72
78
  - test/test_revision.rb
73
79
  has_rdoc: