rack-revision 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 572e54825a1905f7d369a997922a7d6c3d9031f7
4
- data.tar.gz: a5411935f6ae46862d16ddcee5efc3c0643325f7
2
+ SHA256:
3
+ metadata.gz: 2284692d25fe68e54b0842fbeed953ea7727cebe427bc1027ac18ca2329b2ff7
4
+ data.tar.gz: 40319f9c5ca70b8edf3c610846575e3a5b83862bcadccbbc87a1d175a08d8f6c
5
5
  SHA512:
6
- metadata.gz: f771123d5a308206c920696f2c152d22cc40b99f7f13ea977a071edeb8d5dc0de42b160dd8b19a9b0f467fd643c579d5eb416b65a121221b804d10a86b1bd901
7
- data.tar.gz: 5dbd53b2ecc0322bbe2cce1a62b2d6736f20a8b5a59bdba61480e2e7aab5f900e7fb2b07a01b3644c9b83264e1e8e0769ef08f4a96ace13a60e1b8ad4f351817
6
+ metadata.gz: f2346818a69159a398f0be3d81104841f43b183b7609ba0a9c21f6bb7b3a070f40ad7c85bfda185388c81a4a4313247c8bc568e68253e20ff34ca8b20a8deef1
7
+ data.tar.gz: 6aff733c7f9fdca284c41af3545ee8d51997972afa018bba66441e79169bb37b580cc27e4d9928dbf15ba6636110973d0f003839b2cf9c9d84722b930ebd342a
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
- - 1.9.3
6
- - 2.0.0
3
+ - 2.3
4
+ - 2.4
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2012-2020 Dan Sosedoff, dan.sosedoff@gmail.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -3,7 +3,8 @@
3
3
  Rack::Revision is a quick drop-in component to enable code revision tracking.
4
4
  It adds `X-Revision` header with the code revision from capistrano's REVISION file.
5
5
 
6
- [![Build Status](https://travis-ci.org/sosedoff/rack-revision.png?branch=master)](https://travis-ci.org/sosedoff/rack-revision)
6
+ [![Build Status](https://img.shields.io/travis/sosedoff/rack-revision.svg)](https://travis-ci.org/sosedoff/rack-revision)
7
+ [![Gem Version](https://img.shields.io/gem/v/rack-revision.svg)](http://badge.fury.io/rb/rack-revision)
7
8
 
8
9
  ## Installation
9
10
 
@@ -43,10 +44,35 @@ run Sinatra::Application
43
44
 
44
45
  Available options:
45
46
 
46
- - `:header` - Sets a custom revision header. Default: `X-Revision`
47
- - `:filename` - Sets a filename with revision data. Default: `REVISION`
48
- - `:default` - Sets a revision value if file does not exist. Default: UNDEFINED
49
- - `:rack_env` - Sets a revision value to Rack's `env` hash. Default: `env['rack.app_revision']`
47
+ - `:header` - Changes revision header name. Default: `X-Revision`
48
+ - `:filename` - Changes the revision filename. Default: `REVISION`
49
+ - `:rack_env` - Changes Rack environment key for revision. Default: `env['rack.app_revision']`
50
+ - `:env_var` - Sets revision value from an environment variable. Default: `RACK_REVISION`
51
+ - `:default` - Sets revision value if env var or a file with revision does not exist. Default: `UNDEFINED`
52
+
53
+ ## Example
54
+
55
+ To see what the header might look like, run a curl command:
56
+
57
+ ```
58
+ curl -i -X HEAD "http://yourdomain.com"
59
+ ```
60
+
61
+ Example response:
62
+
63
+ ```
64
+ HTTP/1.1 200 OK
65
+ Server: nginx/1.4.4
66
+ Content-Type: text/html; charset=utf-8
67
+ Connection: keep-alive
68
+ X-UA-Compatible: IE=Edge,chrome=1
69
+ ETag: "5e622b6dab40d3cb8ad8a4bd51627a59"
70
+ Cache-Control: max-age=0, private, must-revalidate
71
+ X-Request-Id: ae07ad30bd857788bebfa1421576f96e
72
+ X-Runtime: 0.022007
73
+ X-Rack-Cache: miss
74
+ X-Revision: a3de2043d4cea6182e511c9c73f57f4f1e0dbc2b
75
+ ```
50
76
 
51
77
  ## Test
52
78
 
@@ -58,21 +84,6 @@ rake test
58
84
 
59
85
  ## License
60
86
 
61
- Copyright (c) 2012-2013 Dan Sosedoff.
62
-
63
- Permission is hereby granted, free of charge, to any person obtaining a copy of
64
- this software and associated documentation files (the "Software"), to deal in
65
- the Software without restriction, including without limitation the rights to
66
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
67
- the Software, and to permit persons to whom the Software is furnished to do so,
68
- subject to the following conditions:
69
-
70
- The above copyright notice and this permission notice shall be included in all
71
- copies or substantial portions of the Software.
87
+ The MIT License
72
88
 
73
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
75
- FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
76
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
77
- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
78
- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
89
+ Copyright (c) 2012-2020 Dan Sosedoff <dan.sosedoff@gmail.com>
@@ -32,17 +32,23 @@ module Rack
32
32
  protected
33
33
 
34
34
  def revision
35
- @@revision ||= read_revision
35
+ @@revision ||= (fetch_from_env || fetch_from_file || fetch_default)
36
36
  end
37
37
 
38
- def read_revision
39
- if File.exists?(detected_filename)
40
- File.read(detected_filename).strip
41
- else
42
- @options[:default]
38
+ def fetch_from_env
39
+ ENV[@options[:env_var]]
40
+ end
41
+
42
+ def fetch_from_file
43
+ if ::File.exists?(detected_filename)
44
+ ::File.read(detected_filename).strip
43
45
  end
44
46
  end
45
47
 
48
+ def fetch_default
49
+ @options[:default]
50
+ end
51
+
46
52
  def detected_filename
47
53
  @file ||= (@options[:filename] =~ /\A\// ? @options[:filename] : File.join(Dir.pwd, @options[:filename]))
48
54
  end
@@ -51,6 +57,7 @@ module Rack
51
57
  @options = {
52
58
  :header => options[:header].nil? ? "X-Revision" : options[:header],
53
59
  :rack_env => options[:rack_env].nil? ? "rack.app_revision" : options[:rack_env],
60
+ :env_var => options[:env_var] || "RACK_REVISION",
54
61
  :filename => options[:filename] || "REVISION",
55
62
  :default => options[:default] || "UNDEFINED"
56
63
  }
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Revision
3
- VERSION = "1.0.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -10,7 +10,11 @@ Gem::Specification.new do |s|
10
10
  s.email = ["dan.sosedoff@gmail.com"]
11
11
 
12
12
  s.add_runtime_dependency 'rack', '>= 1.0'
13
+
14
+ s.add_development_dependency 'rake', '~> 10.0'
13
15
  s.add_development_dependency 'rack-test', '>= 0'
16
+ s.add_development_dependency 'simplecov', '~> 0.8'
17
+ s.add_development_dependency 'test-unit', '>= 0'
14
18
 
15
19
  s.files = `git ls-files`.split("\n")
16
20
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,14 +1,17 @@
1
- require 'test/unit'
2
- require 'rack/test'
3
- require 'rack/revision'
4
- require 'fileutils'
1
+ require "simplecov"
2
+ SimpleCov.start
3
+
4
+ require "test/unit"
5
+ require "rack/test"
6
+ require "rack/revision"
7
+ require "fileutils"
5
8
 
6
9
  class TestRevision < Test::Unit::TestCase
7
10
  include Rack::Test::Methods
8
11
 
9
12
  def default_app
10
13
  lambda do |env|
11
- headers = {'Content-Type' => "text/html"}
14
+ headers = {"Content-Type" => "text/html"}
12
15
  [200, headers, ["OK"]]
13
16
  end
14
17
  end
@@ -24,11 +27,11 @@ class TestRevision < Test::Unit::TestCase
24
27
  attr_writer :app
25
28
 
26
29
  def setup
27
- FileUtils.mkdir('./test/tmp')
30
+ FileUtils.mkdir("./test/tmp")
28
31
  end
29
32
 
30
33
  def teardown
31
- FileUtils.rm_rf('./test/tmp')
34
+ FileUtils.rm_rf("./test/tmp")
32
35
  end
33
36
 
34
37
  def test_revision_request
@@ -42,8 +45,8 @@ class TestRevision < Test::Unit::TestCase
42
45
  self.app.reset_revision
43
46
  get app_url
44
47
 
45
- assert_not_nil last_response.headers['X-REVISION']
46
- assert_not_nil last_response.headers['X-Revision']
48
+ assert_not_nil last_response.headers["X-REVISION"]
49
+ assert_not_nil last_response.headers["X-Revision"]
47
50
  end
48
51
 
49
52
  def test_blank
@@ -51,15 +54,15 @@ class TestRevision < Test::Unit::TestCase
51
54
  self.app.reset_revision
52
55
  get app_url
53
56
 
54
- assert_nil last_response.headers['X-REVISION']
55
- assert_nil last_response.headers['X-Revision']
57
+ assert_nil last_response.headers["X-REVISION"]
58
+ assert_nil last_response.headers["X-Revision"]
56
59
  end
57
60
 
58
61
  def test_default_value
59
62
  self.app.reset_revision
60
63
  get app_url
61
64
 
62
- assert_equal "UNDEFINED", last_response.headers['X-Revision']
65
+ assert_equal "UNDEFINED", last_response.headers["X-Revision"]
63
66
  end
64
67
 
65
68
  def test_custom_value
@@ -67,7 +70,7 @@ class TestRevision < Test::Unit::TestCase
67
70
  self.app.reset_revision
68
71
 
69
72
  get app_url
70
- assert_equal "FOOBAR", last_response.headers['X-Revision']
73
+ assert_equal "FOOBAR", last_response.headers["X-Revision"]
71
74
  end
72
75
 
73
76
  def test_custom_header
@@ -75,44 +78,44 @@ class TestRevision < Test::Unit::TestCase
75
78
  self.app.reset_revision
76
79
 
77
80
  get app_url
78
- assert_not_nil last_response.headers['FOOBAR']
81
+ assert_not_nil last_response.headers["FOOBAR"]
79
82
  end
80
83
 
81
84
  def test_custom_filename
82
- File.open('./test/tmp/REVISION', 'w') { |f| f.write('qwe123') }
85
+ File.open("./test/tmp/REVISION", "w") { |f| f.write("qwe123") }
83
86
 
84
- self.app = Rack::Revision.new(default_app, :filename => './test/tmp/REVISION')
87
+ self.app = Rack::Revision.new(default_app, :filename => "./test/tmp/REVISION")
85
88
  self.app.reset_revision
86
89
 
87
90
  get app_url
88
- assert_equal 'qwe123', last_response.headers['X-Revision']
91
+ assert_equal "qwe123", last_response.headers["X-Revision"]
89
92
  end
90
93
 
91
94
  def test_custom_filename_starting_from_root
92
- File.open('./test/tmp/REVISION', 'w') { |f| f.write('qwe123') }
95
+ File.open("./test/tmp/REVISION", "w") { |f| f.write("qwe123") }
93
96
  filename = File.expand_path("./test/tmp/REVISION")
94
97
 
95
98
  self.app = Rack::Revision.new(default_app, :filename => filename)
96
99
  self.app.reset_revision
97
100
 
98
101
  get app_url
99
- assert_equal 'qwe123', last_response.headers['X-Revision']
102
+ assert_equal "qwe123", last_response.headers["X-Revision"]
100
103
  end
101
104
 
102
105
  def test_env_is_present
103
106
  self.app.reset_revision
104
107
  get app_url
105
108
 
106
- assert_not_nil last_request.env['rack.app_revision']
109
+ assert_not_nil last_request.env["rack.app_revision"]
107
110
  end
108
111
 
109
112
  def test_custom_env
110
- self.app = Rack::Revision.new(default_app, :rack_env => 'rack.custom_env')
113
+ self.app = Rack::Revision.new(default_app, :rack_env => "rack.custom_env")
111
114
  self.app.reset_revision
112
115
  get app_url
113
116
 
114
- assert_nil last_request.env['rack.app_revision']
115
- assert_not_nil last_request.env['rack.custom_env']
117
+ assert_nil last_request.env["rack.app_revision"]
118
+ assert_not_nil last_request.env["rack.custom_env"]
116
119
  end
117
120
 
118
121
  def test_disable_env
@@ -120,6 +123,25 @@ class TestRevision < Test::Unit::TestCase
120
123
  self.app.reset_revision
121
124
  get app_url
122
125
 
123
- assert_nil last_request.env['rack.app_revision']
126
+ assert_nil last_request.env["rack.app_revision"]
127
+ end
128
+
129
+ def test_from_env_var
130
+ self.app = Rack::Revision.new(default_app)
131
+ self.app.reset_revision
132
+
133
+ ENV["RACK_REVISION"] = "revision"
134
+ get app_url
135
+ assert_equal "revision", last_response.headers["X-Revision"]
136
+ end
137
+
138
+ def test_from_custom_env_var
139
+ self.app = Rack::Revision.new(default_app, env_var: "SERVICE_REVISION")
140
+ self.app.reset_revision
141
+
142
+ ENV["RACK_REVISION"] = "bad"
143
+ ENV["SERVICE_REVISION"] = "good"
144
+ get app_url
145
+ assert_equal "good", last_response.headers["X-Revision"]
124
146
  end
125
147
  end
metadata CHANGED
@@ -1,41 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-revision
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Sosedoff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-19 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rack-test
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - '>='
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
32
74
  - !ruby/object:Gem::Version
33
75
  version: '0'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - '>='
80
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
82
  version: '0'
41
83
  description: Adds an extra X-REVISION header with source code revision string (git,
@@ -46,9 +88,10 @@ executables: []
46
88
  extensions: []
47
89
  extra_rdoc_files: []
48
90
  files:
49
- - .gitignore
50
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".travis.yml"
51
93
  - Gemfile
94
+ - LICENSE
52
95
  - README.md
53
96
  - Rakefile
54
97
  - lib/rack/revision.rb
@@ -64,17 +107,16 @@ require_paths:
64
107
  - lib
65
108
  required_ruby_version: !ruby/object:Gem::Requirement
66
109
  requirements:
67
- - - '>='
110
+ - - ">="
68
111
  - !ruby/object:Gem::Version
69
112
  version: '0'
70
113
  required_rubygems_version: !ruby/object:Gem::Requirement
71
114
  requirements:
72
- - - '>='
115
+ - - ">="
73
116
  - !ruby/object:Gem::Version
74
117
  version: '0'
75
118
  requirements: []
76
- rubyforge_project:
77
- rubygems_version: 2.0.5
119
+ rubygems_version: 3.0.6
78
120
  signing_key:
79
121
  specification_version: 4
80
122
  summary: Code ravision rack middleware