sickill-rack-revision-info 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack_revision_info.rb +45 -0
- metadata +53 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
module Rack
|
2
|
+
class RevisionInfo
|
3
|
+
|
4
|
+
def initialize(app, opts={})
|
5
|
+
@app = app
|
6
|
+
path = opts[:path] or raise ArgumentError, "You must specify directory of your local repository!"
|
7
|
+
revision, date = get_revision_info(path)
|
8
|
+
@revision_info = "Revision #{revision || 'unknown'}"
|
9
|
+
@revision_info << " (#{date.strftime("%Y-%m-%d %H:%M:%S %Z")})" if date
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env)
|
13
|
+
status, headers, body = @app.call(env)
|
14
|
+
if headers['Content-Type'] == 'text/html' && !Rack::Request.new(env).xhr?
|
15
|
+
body << "\n" << %(<!-- #{@revision_info} -->)
|
16
|
+
end
|
17
|
+
[status, headers, body]
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def get_revision_info(path)
|
23
|
+
case detect_type(path)
|
24
|
+
when :git
|
25
|
+
info = `cd #{path}; LC_ALL=C git log -1 --pretty=medium`
|
26
|
+
revision = info[/commit\s([a-z0-9]+)/, 1]
|
27
|
+
date = (d = info[/Date:\s+(.+)$/, 1]) && (DateTime.parse(d) rescue nil)
|
28
|
+
when :svn
|
29
|
+
info = `cd #{path}; LC_ALL=C svn info`
|
30
|
+
revision = info[/Revision:\s(\d+)$/, 1]
|
31
|
+
date = (d = info[/Last Changed Date:\s([^\(]+)/, 1]) && (DateTime.parse(d.strip) rescue nil)
|
32
|
+
else
|
33
|
+
revision, date = nil, nil
|
34
|
+
end
|
35
|
+
[revision, date]
|
36
|
+
end
|
37
|
+
|
38
|
+
def detect_type(path)
|
39
|
+
return :git if ::File.directory?(::File.join(path, ".git"))
|
40
|
+
return :svn if ::File.directory?(::File.join(path, ".svn"))
|
41
|
+
:unknown
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sickill-rack-revision-info
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.2"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcin Kulik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-31 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: marcin.kulik@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/rack_revision_info.rb
|
26
|
+
has_rdoc: false
|
27
|
+
homepage: http://sickill.net
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: "0"
|
38
|
+
version:
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
requirements: []
|
46
|
+
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.2.0
|
49
|
+
signing_key:
|
50
|
+
specification_version: 2
|
51
|
+
summary: Rack middleware showing current git (or svn) revision number of application
|
52
|
+
test_files: []
|
53
|
+
|