Commit 4a1146c77b340a7f1a1aa09da273766112b32298

Authored by Nathan Broadbent
1 parent d0e170ee
Exists in master and in 1 other branch production

refactored issue_tracker helper methods

Showing 1 changed file with 10 additions and 19 deletions   Show diff stats
app/helpers/application_helper.rb
1 module ApplicationHelper 1 module ApplicationHelper
2 -  
3 -  
4 - def lighthouse_tracker? object  
5 - object.issue_tracker_type == "lighthouseapp"  
6 - end  
7 - 2 +
8 def user_agent_graph(error) 3 def user_agent_graph(error)
9 tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)} 4 tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)}
10 create_percentage_table(tallies, :total => error.notices.count) 5 create_percentage_table(tallies, :total => error.notices.count)
11 end 6 end
12 - 7 +
13 def pretty_user_agent(user_agent) 8 def pretty_user_agent(user_agent)
14 (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}" 9 (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}"
15 end 10 end
16 - 11 +
17 def tally(collection, &block) 12 def tally(collection, &block)
18 collection.inject({}) do |tallies, item| 13 collection.inject({}) do |tallies, item|
19 value = yield item 14 value = yield item
@@ -21,7 +16,7 @@ module ApplicationHelper @@ -21,7 +16,7 @@ module ApplicationHelper
21 tallies 16 tallies
22 end 17 end
23 end 18 end
24 - 19 +
25 def create_percentage_table(tallies, options={}) 20 def create_percentage_table(tallies, options={})
26 total = (options[:total] || total_from_tallies(tallies)) 21 total = (options[:total] || total_from_tallies(tallies))
27 percent = 100.0 / total.to_f 22 percent = 100.0 / total.to_f
@@ -29,21 +24,17 @@ module ApplicationHelper @@ -29,21 +24,17 @@ module ApplicationHelper
29 .sort {|a, b| a[0] <=> b[0]} 24 .sort {|a, b| a[0] <=> b[0]}
30 render :partial => "errs/tally_table", :locals => {:rows => rows} 25 render :partial => "errs/tally_table", :locals => {:rows => rows}
31 end 26 end
32 - 27 +
33 def total_from_tallies(tallies) 28 def total_from_tallies(tallies)
34 tallies.values.inject(0) {|sum, n| sum + n} 29 tallies.values.inject(0) {|sum, n| sum + n}
35 end 30 end
36 private :total_from_tallies 31 private :total_from_tallies
37 -  
38 - def redmine_tracker? object  
39 - object.issue_tracker_type == "redmine"  
40 - end  
41 32
42 - def pivotal_tracker? object  
43 - object.issue_tracker_type == "pivotal" 33 + %w(lighthouseapp redmine pivotal fogbugz mingle).each do |tracker|
  34 + define_method("#{tracker}_tracker?".to_sym) do |object|
  35 + object.issue_tracker_type == tracker
  36 + end
44 end 37 end
45 38
46 - def fogbugz_tracker? object  
47 - object.issue_tracker_type == 'fogbugz'  
48 - end  
49 end 39 end
  40 +