Class: Barkeeper

Inherits:
Object
  • Object
show all
Defined in:
lib/barkeep.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rendererObject

Returns the value of attribute renderer.



15
16
17
# File 'lib/barkeep.rb', line 15

def renderer
  @renderer
end

Instance Method Details

#branch_infoObject



64
65
66
# File 'lib/barkeep.rb', line 64

def branch_info
  %(<dt>Branch:</dt><dd><a href="#{branch_link_attributes[:href]}">#{grit_info[:branch]}</a></dd>)
end


95
96
97
98
99
100
# File 'lib/barkeep.rb', line 95

def branch_link_attributes
  {
    :href => "#{github_url}/tree/#{grit_info[:branch]}",
    :title => grit_info[:message]
  }
end

#commit_author_infoObject



72
73
74
# File 'lib/barkeep.rb', line 72

def commit_author_info
  %(<dt>Who:</dt><dd>#{grit_info[:last_author]}</dd>)
end

#commit_date_infoObject



76
77
78
79
# File 'lib/barkeep.rb', line 76

def commit_date_info
  short_date = (grit_info[:date].respond_to?(:strftime) ? grit_info[:date].strftime("%d %B, %H:%M") : short_date.to_s)
  %(<dt>When:</dt><dd title="#{grit_info[:date].to_s}">#{short_date}</dd>)
end


102
103
104
105
106
107
# File 'lib/barkeep.rb', line 102

def commit_link_attributes
  {
    :href => "#{github_url}/commit/#{grit_info[:commit]}",
    :title => "committed #{grit_info[:date]} by #{grit_info[:last_author]}"
  }
end

#commit_sha_infoObject



68
69
70
# File 'lib/barkeep.rb', line 68

def commit_sha_info
  %(<dt>Commit:</dt><dd><a href="#{commit_link_attributes[:href]}" title="#{commit_link_attributes[:title]}">#{(grit_info[:commit] || "").slice(0,8)}</a></dd>)
end

#configObject



17
18
19
# File 'lib/barkeep.rb', line 17

def config
  @config ||= JSON.parse(File.read("config/barkeep.json"))
end

#github_urlObject



87
88
89
# File 'lib/barkeep.rb', line 87

def github_url
  config['github_url']
end

#grit_infoObject



91
92
93
# File 'lib/barkeep.rb', line 91

def grit_info
  GitWrapper.instance
end

#load?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/barkeep.rb', line 21

def load?
  if defined?(Rails)
    this_env = Rails.env
  elsif defined?(Sinatra)
    this_env = Sinatra::Application.settings.environment
  end
  config['environments'].include?(this_env.to_s)
end

#render_toolbarObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/barkeep.rb', line 35

def render_toolbar
  return unless load? && grit_info.repository?

  %(
    <dl id="barkeep">
    #{
      config['panes'].map do |name|
        if name =~ /^(p|partial) (.*)/
          if renderer.respond_to?(:render_to_string)
            renderer.send(:render_to_string, {:partial => $2})
          else
            renderer.send(:render, {:partial => $2})  
          end
        else
          send(name)
        end
      end.join('')
    }
    <dd class="close">
      <a href="#" onclick="c = document.getElementById('barkeep'); c.parentNode.removeChild(c); return false" title="Close me!">&times;</a>
    </dd>
    </dl>
  ).html_safe
end

#rpm_enabled?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
114
115
116
117
# File 'lib/barkeep.rb', line 109

def rpm_enabled?
  if defined?(NewRelic)
    if defined?(NewRelic::Control)
      !NewRelic::Control.instance['skip_developer_route']
    else
      !NewRelic::Config.instance['skip_developer_route']
    end
  end
end

#rpm_request_infoObject



81
82
83
84
85
# File 'lib/barkeep.rb', line 81

def rpm_request_info
  if rpm_enabled?
    %(<dt><a href="/newrelic">RPM:</a></dt><dd><a href="#{rpm_url}">request</a></dd>)
  end
end

#rpm_sample_idObject



119
120
121
# File 'lib/barkeep.rb', line 119

def rpm_sample_id
  NewRelic::Agent.instance.transaction_sampler.current_sample_id
end

#rpm_urlObject



123
124
125
# File 'lib/barkeep.rb', line 123

def rpm_url
  "/newrelic/show_sample_detail/#{rpm_sample_id}"
end

#stylesObject



30
31
32
33
# File 'lib/barkeep.rb', line 30

def styles
  return unless load?
  %(<style>#{File.read(File.expand_path(File.dirname(__FILE__) + "/default.css"))}</style>).html_safe
end