Daily Refactor #43: Extract Method in StuffToDoController

The Refactoring

Today I used extract method to start cleaning up the new TimeGrid code I recently merged into the StuffToDo plugin.

Before

1
2
3
4
5
# app/controllers/stuff_to_do_controller.rb
class StuffToDoController  "#{Issue.table_name}.id ASC")
    @time_entry = TimeEntry.new
  end
end

After

1
2
3
4
5
6
7
8
9
10
11
# app/controllers/stuff_to_do_controller.rb
class StuffToDoController  "#{Issue.table_name}.id ASC")
    @time_entry = TimeEntry.new
  end
 
  def parse_date_from_params
    date = Date.parse(params[:date]) if params[:date]
    date ||= Date.civil(params[:year].to_i, params[:month].to_i, params[:day].to_i) if params[:year] && params[:month] && params[:day]
    date ||= Date.today
  end
end

Review

This was a simple refactoring which helps to separate the code into better parts. The three lines to parse the date are needed by the TimeGrid, but it isn’t a core part of how the TimeGrid so it’s better to have it in a utility method.

Reference commit