Ever since I started my Daily Refactorings I’ve been noticing more and more little things to improve code. The nice thing is that I’ve built up the confidence to tackle the easy ones the moment I see them. Like this one I found while working on a new Redmine plugin for a client. It’s nothing …
Tag: refactoring
Daily Refactor #28: Decouple flash messages from Attachment#attach_files
The Refactoring After thinking about yesterday’s refactor, I noticed that setting the flash message is going to cause problems for future refactorings since it’s trying to break the MVC constraints. Today I found a way to decouple tracking the failed saves while keeping the flash messages up in the controllers. Before 1 2 3 4 …
Daily Refactor #27: Move Method to the Attachment Model
The Refactoring Today I used move method to refactor part of Redmine that had a TODO comment since 2007. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # app/controllers/application_controller.rb class ApplicationController 0 a = Attachment.create(:container => obj, :file => file, :description => attachment['description'].to_s.strip, :author => User.current) a.new_record? …
Daily Refactor #26: Convert Procedural Design to Objects in #issue_update
The Refactoring Now that I have a single method to start refactoring, it’s time to start digging into #issue_update. The first smell I see is that the method is working on an Issue, TimeEntry, and Attachments all at once, jumping between the three procedurally. So first I needed to separate these three objects. Before 1 …
Daily Refactor #25: Extract method in IssuesController#update
The Refactoring This refactoring is what I call the magic trick refactor; it looks like a lot is going on but in reality it’s just smoke and mirrors! Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 …