I decided to move to another section of Invoice before I tackle the finder used in Invoice#open. I’m thinking about using a simple state machine for the different invoice states and that will require some redesign. I found it’s best to think about redesigns for time before starting on them. The Refactoring Today I refactored …
Tag: ruby
Daily Refactor #74: Extract Method in Invoice
The Refactoring While adding tests to my Redmine Invoice plugin, I found the following nasty bit of logic. Before 1 2 3 4 5 6 7 class Invoice < ActiveRecord::Base def self.open invoices = self.find(:all) return invoices.select { |invoice| !invoice.fully_paid? && !invoice.late? } end endclass Invoice < ActiveRecord::Base def self.open invoices = self.find(:all) return …
Daily Refactor #73: Move Method to before_filter in InvoiceController
I’m starting to refactor my Redmine Invoice plugin now. This plugin is over two years old now and it’s code has seen better days. The Refactoring The Rails Best Practices gem showed me a quick refactoring to remove some duplication from InvoiceController using a before_filter. Before 1 2 3 4 5 6 7 8 9 …
Daily Refactor #72: Move Method in KanbansController
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 …
Daily Refactor #71: Extract Method in KanbansController to before_filter
The code in the Redmine Merge plugin looks pretty good so I’m going back to my Redmine Kanban plugin. Today’s refactoring was guided by the Rails Best Practices gem. This gem uses static code analysis to search for common smells in Rails applications. Running it on Redmine Kanban showed several smells I can tackle: ./app/controllers/kanbans_controller.rb:8,13 …