Skip to content

Commit

Permalink
Memoizing issue templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Recobra committed Apr 5, 2011
1 parent e012272 commit d55b077
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/models/issue_tracker.rb
Expand Up @@ -28,7 +28,7 @@ def create_redmine_issue err
RedmineClient::Issue.site = account + "/projects/:project_id"
issue = RedmineClient::Issue.new(:project_id => project_id)
issue.subject = issue_title err
issue.description = ERB.new(File.read(Rails.root + "app/views/errs/redmine_body.txt.erb").gsub(/^\s*/, '')).result(binding)
issue.description = self.class.redmine_body_template.result(binding)
issue.save!
err.update_attribute :issue_link, "#{RedmineClient::Issue.site.to_s.sub(/#{RedmineClient::Issue.site.path}$/, '')}#{RedmineClient::Issue.element_path(issue.id, :project_id => project_id)}".sub(/\.xml$/, '')
end
Expand All @@ -43,7 +43,7 @@ def create_lighthouseapp_issue err
ticket = Lighthouse::Ticket.new(:project_id => project_id)
ticket.title = issue_title err

ticket.body = ERB.new(File.read(Rails.root + "app/views/errs/lighthouseapp_body.txt.erb").gsub(/^\s*/, '')).result(binding)
ticket.body = self.class.lighthouseapp_body_template.result(binding)

ticket.tags << "errbit"
ticket.save!
Expand All @@ -65,4 +65,14 @@ def check_params
errors.add(:base, message)
end
end

class << self
def lighthouseapp_body_template
@@lighthouseapp_body_template ||= ERB.new(File.read(Rails.root + "app/views/errs/lighthouseapp_body.txt.erb").gsub(/^\s*/, ''))
end

def redmine_body_template
@@redmine_body_template ||= ERB.new(File.read(Rails.root + "app/views/errs/redmine_body.txt.erb").gsub(/^\s*/, ''))
end
end
end

0 comments on commit d55b077

Please sign in to comment.