Daily Refactor #54: Move Method to KanbanPane

The Refactoring

Today I did another simple refactoring by moving a method from Kanban to KanbanPane.

Before

1
2
3
4
5
6
7
8
9
10
11
12
# app/models/kanban.rb
class Kanban
  # Sort and group a set of issues based on IssuePriority#position
  def group_by_priority_position(issues)
    return issues.group_by {|issue|
      issue.priority
    }.sort {|a,b|
      a[0].position  b[0].position
    }
  end
 
end
1
2
3
4
# app/models/kanban_pane.rb
class KanbanPane
  # ...
end
1
2
3
4
5
6
7
8
9
10
# app/models/kanban_pane/backlog_pane.rb
class KanbanPane::BacklogPane < KanbanPane
  def get_issues(options={})
    # ...
 
    # TODO: Remove wrapper
    kanban = Kanban.new
    return kanban.send(:group_by_priority_position, issues)
  end
end
1
2
3
4
5
6
7
8
9
10
# app/models/kanban_pane/quick_pane.rb
class KanbanPane::QuickPane < KanbanPane
  def get_issues(options={})
    # ...
 
    # TODO: Remove wrapper
    kanban = Kanban.new
    return kanban.send(:group_by_priority_position, issues)
  end
end

After

1
2
3
4
# app/models/kanban.rb
class Kanban
  # ...
end
1
2
3
4
5
6
7
8
9
10
11
# app/models/kanban_pane.rb
class KanbanPane
  # Sort and group a set of issues based on IssuePriority#position
  def group_by_priority_position(issues)
    return issues.group_by {|issue|
      issue.priority
    }.sort {|a,b|
      a[0].position  b[0].position
    }
  end
end
1
2
3
4
5
6
7
# app/models/kanban_pane/backlog_pane.rb
class KanbanPane::BacklogPane < KanbanPane
  def get_issues(options={})
    # ...
    return group_by_priority_position(issues)
  end
end
1
2
3
4
5
6
7
# app/models/kanban_pane/quick_pane.rb
class KanbanPane::QuickPane < KanbanPane
  def get_issues(options={})
    # ...
    return group_by_priority_position(issues)
  end
end

Review

Similar to yesterday’s refactoring, this one moves the #group_by_priority_position method onto KanbanPane where it’s used.

Reference commit