Daily Refactor #46: Extract Method for Kanban panes – Part 2

This is the second in a series of refactorings to clean up how the Kanban class gets it’s pane data.

The Refactoring

Using extract method again, I was able to merge #get_active and #get_testing so they both use a new method #issues_from_kanban_issue.

Before

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# app/models/kanban.rb
class Kanban
  def get_active
    active = {}
    @users.each do |user|
      active[user] = KanbanIssue.find_active(user.id)
    end unless @users.blank?
    active
  end
 
  def get_testing
    testing = {}
    @users.each do |user|
      testing[user] = KanbanIssue.find_testing(user.id)
    end unless @users.blank?
    testing
  end
end

After

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# app/models/kanban.rb
class Kanban
  def get_active
    issues_from_kanban_issue(:active)
  end
 
  def get_testing
    issues_from_kanban_issue(:testing)
  end
 
  private
 
  def issues_from_kanban_issue(pane)
    return {} unless [:active, :testing].include?(pane)
 
    issues = {}
    @users.each do |user|
      issues[user] = KanbanIssue.send('find_' + pane.to_s, user.id)
    end unless @users.blank?
    issues
 
  end
end

Review

This gets me one step closer to uniting all of the Kanban#get_* methods.

Reference commit

Share

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

Related posts:

  1. Redmine Refactor #140: Extract Method WikiController#edit to #update
  2. Redmine Refactor #118: Split Edit Method in NewsController
  3. Redmine Refactor #88: Extract Method from move and perform_move
  4. Daily Refactor #47: Extract Method for Kanban panes – Part 3
  5. Daily Refactor #38: Extract Method in StuffToDo

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