statusz 0.1.0.pre → 0.1.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,18 +9,15 @@ get "/" do
9
9
  end
10
10
 
11
11
  get "/statusz.:format" do
12
- case params[:format]
13
- when "html"
14
- when "json"
15
- content_type :json
16
- else
17
- halt 404, "No such page."
18
- end
12
+ halt(404, "No such page") unless %w{txt json html}.include? params[:format]
13
+ format = (params[:format] == "txt") ? :text : params[:format].to_sym
14
+ content_type format
15
+
19
16
  # Generate some dynamic content:
20
17
  db_host = "dbslave#{Random.rand(4)}.example.com"
21
18
 
22
19
  # Include it in our statusz output:
23
- Statusz.render_from_json("./statusz.json", params[:format].to_sym, "db server" => db_host)
20
+ Statusz.render_from_json("./statusz.json", format, "db server" => db_host)
24
21
  end
25
22
 
26
23
  __END__
@@ -46,7 +43,7 @@ __END__
46
43
  </style>
47
44
  </head>
48
45
  <body>
49
- This is an example of a web app that uses statusz. Go to <a href="/statusz.html">statusz.html</a> or
50
- <a href="/statusz.json">statusz.json</a> to see it in action.
46
+ This is an example of a web app that uses statusz. Go to <a href="/statusz.html">statusz.html</a>, <a
47
+ href="/statusz.txt">statusz.txt</a>, or <a href="/statusz.json">statusz.json</a> to see it in action.
51
48
  </body>
52
49
  </html>
data/lib/statusz.rb CHANGED
@@ -54,7 +54,11 @@ module Statusz
54
54
  def self.render(fields, format)
55
55
  case format
56
56
  when :text
57
- fields.map { |name, value| "#{name}:\n#{value}" }.join("\n\n")
57
+ # For readability, it's nice to have the massive 'all commits' field be the last one.
58
+ all_commits = fields.delete "all commits"
59
+ fields_with_commits_last = fields.map { |name, value| [name, value] }
60
+ fields_with_commits_last << all_commits if all_commits
61
+ fields_with_commits_last.map { |name, value| "#{name}:\n#{value}" }.join("\n\n")
58
62
  when :json
59
63
  fields.to_json
60
64
  when :html
@@ -1,3 +1,3 @@
1
1
  module Statusz
2
- VERSION = "0.1.0.pre"
2
+ VERSION = "0.1.0.pre.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: statusz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre
4
+ version: 0.1.0.pre.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack