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 1 module ApplicationHelper
2   -
3   -
4   - def lighthouse_tracker? object
5   - object.issue_tracker_type == "lighthouseapp"
6   - end
7   -
  2 +
8 3 def user_agent_graph(error)
9 4 tallies = tally(error.notices) {|notice| pretty_user_agent(notice.user_agent)}
10 5 create_percentage_table(tallies, :total => error.notices.count)
11 6 end
12   -
  7 +
13 8 def pretty_user_agent(user_agent)
14 9 (user_agent.nil? || user_agent.none?) ? "N/A" : "#{user_agent.browser} #{user_agent.version}"
15 10 end
16   -
  11 +
17 12 def tally(collection, &block)
18 13 collection.inject({}) do |tallies, item|
19 14 value = yield item
... ... @@ -21,7 +16,7 @@ module ApplicationHelper
21 16 tallies
22 17 end
23 18 end
24   -
  19 +
25 20 def create_percentage_table(tallies, options={})
26 21 total = (options[:total] || total_from_tallies(tallies))
27 22 percent = 100.0 / total.to_f
... ... @@ -29,21 +24,17 @@ module ApplicationHelper
29 24 .sort {|a, b| a[0] <=> b[0]}
30 25 render :partial => "errs/tally_table", :locals => {:rows => rows}
31 26 end
32   -
  27 +
33 28 def total_from_tallies(tallies)
34 29 tallies.values.inject(0) {|sum, n| sum + n}
35 30 end
36 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 37 end
45 38  
46   - def fogbugz_tracker? object
47   - object.issue_tracker_type == 'fogbugz'
48   - end
49 39 end
  40 +
... ...