Since I’m all hopped-up on white tea from an early morning meeting, this refactoring is a two in one. The Refactoring I used move method and extract method on the InvoiceController to move the business logic down into the model where it belongs. Before 1 2 3 4 5 6 7 8 9 10 11 …
Tag: redmine
Daily Refactor #76: Replace Temp with Query in Invoice#fully_paid?
The Refactoring Since I refactored Invoice#outstanding yesterday, I can now build on that to refactor Invoice#fully_paid?. Before 1 2 3 class Invoice = self.amount end endclass Invoice = self.amount end end After 1 2 3 4 5 class Invoice < ActiveRecord::Base def fully_paid? outstanding <= 0 end endclass Invoice < ActiveRecord::Base def fully_paid? outstanding <= …
Daily Refactor #75: Inline Temp in Invoices#outstanding
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 …
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 …