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

Share

  • Facebook
  • Twitter
  • HackerNews
  • Reddit
  • Tumblr
  • Delicious
  • Email
  • RSS

Related posts:

  1. Daily Refactor #81: Move last_invoice_number to Model
  2. Daily Refactor #55: Move Pane Configuration To KanbanPane
  3. Daily Refactor #31: Extract Method in IssuesHelper#show_detail
  4. Daily Refactor #30: Move Method into Issue
  5. Daily Refactor #8: Move method in the ReportsController

About Eric Davis

I founded Little Stream Software where I provide Redmine and ChiliProject services to help projects teams. I also created an ebook, Redmine Tips, were I show you how to become more productive using Redmine. I am also the author of Refactoring Redmine, where I go about refactoring Rails using Redmine as an example.

, , ,

Chirk HR     Reuse your existing job applicants »
WP Socializer Aakash Web