rack-revision 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +20 -0
- data/LICENSE +1 -1
- data/README.md +7 -7
- data/lib/rack/revision/version.rb +2 -2
- data/lib/rack/revision.rb +7 -6
- data/test/test_revision.rb +17 -0
- metadata +7 -7
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a12f243a22cd037fa6506a704a1d94cfadd93327412558258ce327560a0b52
|
4
|
+
data.tar.gz: 3aae6d6d5b3e0c0ab0881c1926e5d4c33e1f81f38e54c9c58ee18da27b92f65c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36f785c3e545dd733c9ba45bd3b050df65c1fd90065e4f047274820969655351a5e6425d9582426d092ddafb0659fbcd90ff6b44aafb5def60a995599d306b52
|
7
|
+
data.tar.gz: 4bc2a640b44ac615434a18bafe55236fc2327f97c845600420ca4afebd03d2cf6144a69fb0b2626a5daf99459a228564957aca0288aa7e39fa752533a7a14e62
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Build
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: ['2.6', '2.7', '3.0', '3.1']
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v2
|
13
|
+
- name: Set up Ruby
|
14
|
+
uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby }}
|
17
|
+
- name: Install dependencies
|
18
|
+
run: bundle install
|
19
|
+
- name: Run tests
|
20
|
+
run: bundle exec rake
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2012-
|
3
|
+
Copyright (c) 2012-2022 Dan Sosedoff, dan.sosedoff@gmail.com
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
6
|
this software and associated documentation files (the "Software"), to deal in
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Rack::Revision
|
2
2
|
|
3
|
-
Rack::Revision is a quick drop-in component to enable code revision tracking.
|
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
|
6
|
+
[![Build](https://github.com/sosedoff/rack-revision/actions/workflows/test.yml/badge.svg)](https://github.com/sosedoff/rack-revision/actions/workflows/test.yml)
|
7
7
|
[![Gem Version](https://img.shields.io/gem/v/rack-revision.svg)](http://badge.fury.io/rb/rack-revision)
|
8
8
|
|
9
9
|
## Installation
|
@@ -23,7 +23,7 @@ bundle install
|
|
23
23
|
## Usage
|
24
24
|
|
25
25
|
Rack::Revision is implemented as a piece of Rack middleware and can be used with
|
26
|
-
any Rack-based application. If you have a `config.ru` rackup file you can
|
26
|
+
any Rack-based application. If you have a `config.ru` rackup file you can
|
27
27
|
drop the following snippet (for sinatra app):
|
28
28
|
|
29
29
|
```ruby
|
@@ -44,11 +44,11 @@ run Sinatra::Application
|
|
44
44
|
|
45
45
|
Available options:
|
46
46
|
|
47
|
-
- `:header`
|
47
|
+
- `:header` - Changes revision header name. Default: `X-Revision`
|
48
48
|
- `:filename` - Changes the revision filename. Default: `REVISION`
|
49
49
|
- `:rack_env` - Changes Rack environment key for revision. Default: `env['rack.app_revision']`
|
50
|
-
- `:env_var`
|
51
|
-
- `:default`
|
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
52
|
|
53
53
|
## Example
|
54
54
|
|
@@ -86,4 +86,4 @@ rake test
|
|
86
86
|
|
87
87
|
The MIT License
|
88
88
|
|
89
|
-
Copyright (c) 2012-
|
89
|
+
Copyright (c) 2012-2022 Dan Sosedoff <dan.sosedoff@gmail.com>
|
data/lib/rack/revision.rb
CHANGED
@@ -9,8 +9,9 @@ module Rack
|
|
9
9
|
initialize_options(options)
|
10
10
|
|
11
11
|
@app = app
|
12
|
+
@dir = Dir.pwd
|
12
13
|
end
|
13
|
-
|
14
|
+
|
14
15
|
def call(env)
|
15
16
|
if @options[:rack_env]
|
16
17
|
env[@options[:rack_env]] = revision
|
@@ -28,19 +29,19 @@ module Rack
|
|
28
29
|
def reset_revision
|
29
30
|
@@revision = nil
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
protected
|
33
|
-
|
34
|
+
|
34
35
|
def revision
|
35
36
|
@@revision ||= (fetch_from_env || fetch_from_file || fetch_default)
|
36
37
|
end
|
37
|
-
|
38
|
+
|
38
39
|
def fetch_from_env
|
39
40
|
ENV[@options[:env_var]]
|
40
41
|
end
|
41
42
|
|
42
43
|
def fetch_from_file
|
43
|
-
if ::File.
|
44
|
+
if ::File.exist?(detected_filename)
|
44
45
|
::File.read(detected_filename).strip
|
45
46
|
end
|
46
47
|
end
|
@@ -50,7 +51,7 @@ module Rack
|
|
50
51
|
end
|
51
52
|
|
52
53
|
def detected_filename
|
53
|
-
@file ||= (@options[:filename] =~ /\A\// ? @options[:filename] : File.join(
|
54
|
+
@file ||= (@options[:filename] =~ /\A\// ? @options[:filename] : File.join(@dir, @options[:filename]))
|
54
55
|
end
|
55
56
|
|
56
57
|
def initialize_options(options)
|
data/test/test_revision.rb
CHANGED
@@ -102,6 +102,23 @@ class TestRevision < Test::Unit::TestCase
|
|
102
102
|
assert_equal "qwe123", last_response.headers["X-Revision"]
|
103
103
|
end
|
104
104
|
|
105
|
+
def test_dir_does_not_exist
|
106
|
+
File.write("./test/tmp/REVISION", "example")
|
107
|
+
|
108
|
+
Dir.chdir("./test/tmp") do
|
109
|
+
self.app.reset_revision
|
110
|
+
|
111
|
+
get app_url
|
112
|
+
assert_equal "example", last_response.headers["X-Revision"]
|
113
|
+
|
114
|
+
FileUtils.rm_rf("../tmp")
|
115
|
+
self.app.reset_revision
|
116
|
+
|
117
|
+
get app_url
|
118
|
+
assert_equal "UNDEFINED", last_response.headers["X-Revision"]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
105
122
|
def test_env_is_present
|
106
123
|
self.app.reset_revision
|
107
124
|
get app_url
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-revision
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Sosedoff
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -88,8 +88,8 @@ executables: []
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- ".github/workflows/test.yml"
|
91
92
|
- ".gitignore"
|
92
|
-
- ".travis.yml"
|
93
93
|
- Gemfile
|
94
94
|
- LICENSE
|
95
95
|
- README.md
|
@@ -101,7 +101,7 @@ files:
|
|
101
101
|
homepage: http://github.com/sosedoff/rack-revision
|
102
102
|
licenses: []
|
103
103
|
metadata: {}
|
104
|
-
post_install_message:
|
104
|
+
post_install_message:
|
105
105
|
rdoc_options: []
|
106
106
|
require_paths:
|
107
107
|
- lib
|
@@ -116,8 +116,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
|
-
rubygems_version: 3.
|
120
|
-
signing_key:
|
119
|
+
rubygems_version: 3.3.9
|
120
|
+
signing_key:
|
121
121
|
specification_version: 4
|
122
122
|
summary: Code ravision rack middleware
|
123
123
|
test_files:
|