The Refactoring
Today I used move method to clean up a hack job I made a couple of months ago.
Before
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | class KanbansController < ApplicationController def sync # Brute force update :) Issue.all.each do |issue| KanbanIssue.update_from_issue(issue) end respond_to do |format| format.html { flash[:notice] = l(:kanban_text_notice_sync) redirect_to kanban_path } end end end |
After
1 2 3 4 5 6 7 8 9 10 11 | class KanbansController < ApplicationController def sync Issue.sync_with_kanban respond_to do |format| format.html { flash[:notice] = l(:kanban_text_notice_sync) redirect_to kanban_path } end end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | module RedmineKanban module IssuePatch module ClassMethods # Brute force update :) def sync_with_kanban Issue.all.each do |issue| KanbanIssue.update_from_issue(issue) end end end end end |
Review
This refactoring accomplishes two things:
- It helps someone understand what the
#syncaction in the controller does. - It gives a little handhold for anyone wanting to run the sync from someone else in the code. (e.g. like scripting the sync from a Rake task)
Share
Related posts:
