Tag: ruby

Daily Refactor #41: Consolidate Duplicate Conditional Fragments in StuffToDo

The Refactoring Today I refactored the conditional of StuffToDo#conditions_for_available using a little known library in Redmine called ARCondition. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 # app/models/stuff_to_do.rb class StuffToDo < ActiveRecord::Base def self.conditions_for_available(filter_by, record_id) case filter_by when :user ["assigned_to_id = ? AND #{IssueStatus.table_name}.is_closed = ?", record_id, false ] …

Read more

Daily Refactor #37: Extract Method to Query#sortable_columns

The Refactoring I’m still going off of the flay report for today, this time I’m tackling some duplication in the IssuesController. Before 1 2 3 4 5 6 7 8 9 10 11 12 13 # app/controller/issues_controller.rb class IssuesController "#{Issue.table_name}.id"}.merge(@query.available_columns.inject({}) {|h, c| h[c.name.to_s] = c.sortable; h})) # ... end   def changes retrieve_query sort_init 'id', …

Read more