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? …
Tag: ruby
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 …
Daily Refactor #24: Extract method body in IssuesController#edit
I tackled two refactorings today in order to clean up IssuesController#edit. The Refactoring – #1 This first refactoring moves most of the #edit method’s body into #update, where it belongs. This did cause a some duplication though. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 …
Daily Refactor #23: Extract method in IssuesController#edit
After yesterday’s refactor of the #bulk_edit method, Jean-Philippe Lang finished the refactoring by merging the temporary method I created in the model (Issue#bulk_edit) and simplifying the parameter attributes. Back to the drawing board, it looks like the method with the next highest flog score is #edit. #edit is a pretty complex action in Redmine, since …