Skip to content

Commit

Permalink
use self.display_name to get diagnostic name
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingmachine committed May 11, 2011
1 parent 4f0b2dd commit 7b1238f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/diagnostic.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Healthy
class Diagnostic
class << self
class << self
def info_for(normalized_name)
route = Router.routes[normalized_name]
if ServerIdentity.matches?(route[:servers])
route[:klass].info
route[:klass].new.info
else
`curl -H 'Host: #{Diagnostic.site_host}' http://#{route[:servers].first}/status?info=#{normalized_name}`
`curl -H 'Host: #{Diagnostic.site_host}' http://#{route[:servers].first}/status/#{normalized_name}`
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def add_route(*route)
end

def normalized_name(klass)
instance = klass.new
name = instance.respond_to?(:name) ? instance.name : klass.name
name = klass.respond_to?(:display_name) ? klass.display_name : klass.name
name.downcase.gsub(" ", "")
end
end
Expand Down
8 changes: 7 additions & 1 deletion lib/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ class Server < Sinatra::Base
helpers do
def url_for(path)
"#{request.env['SCRIPT_NAME']}/#{path}"
end
end

def display_name(check)
klass = check.class
klass.respond_to?(:display_name) ? klass.display_name : klass.name
end

end
end
end
16 changes: 9 additions & 7 deletions lib/views/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
<div id="main">
<ul>
<% @checks.each do |check| %>
<li id="<%= check.normalized_name %>">
<% normalized_name = Healthy::Router.normalized_name(check.class) %>
<li id="<%= normalized_name %>">
<h2>
<div class="status <%= check.status %>"><%= check.status.to_s.upcase %></div>
<%= check.name %>
<%= display_name(check) %>
</h2>
<% if check.respond_to?(:info) %>
<a href="<%= url_for(check.normalized_name) %>" class='remote button'><span>run</span></a>
<a href="<%= url_for(normalized_name) %>" class='remote button'><span>run</span></a>
<% end %>
<a href="#" class='close button hide' onclick="$(this).hide().siblings('.info').slideUp(); return false;"><span>close</span></a>
<div class='info'></div>
Expand All @@ -25,12 +26,13 @@
</ul>
<ul id='tools'>
<% @tools.each do |check| %>
<li id="<%=check.normalized_name %>">
<% normalized_name = Healthy::Router.normalized_name(check.class) %>
<li id="<%=normalized_name %>">
<h2>
<div class="status"></div>
<%= check.name %>
<%= display_name(check) %>
</h2>
<a href="<%= url_for(check.normalized_name) %>" class='remote button'><span>run</span></a>
<a href="<%= url_for(normalized_name) %>" class='remote button'><span>run</span></a>
<a href="#" class='close button hide' onclick="$(this).hide().siblings('.info').slideUp(); return false;"><span>close</span></a>
<div class='info'></div>
</li>
Expand All @@ -39,7 +41,7 @@

<h4 id="refresh-msg" class='left'></h4>
<h4 class='right'>
<%= Healthy::Diagnostic.current_server %>
<%= Healthy::ServerIdentity.identity %>
<a href='#headers' onclick="$('#headers').toggle(); return false;">(show headers)</a>
</h4>
<div id='headers'><h6><%= request.env.keys.sort.collect{|n| "#{n} = #{request.env[n]}" }.join('<br>') %></h6></div>
Expand Down
2 changes: 1 addition & 1 deletion spec/router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class WarholCheck
end

class DuchampCheck
def name
def self.display_name
"Moustache Check"
end
end
Expand Down

0 comments on commit 7b1238f

Please sign in to comment.