Thu, 10 Dec 2015 13:50:31 +0900 投稿
0

【Refactor Me】ひとつのメソッドに詰め込み過ぎ

Before

class RequestToAnalyticsService
  def perform(data)
    account           = Account.find(data[:account_id)
    analytics_client  = Analytics::Client.new(Settings.analytics_api_key])

    account_attributes = {
      account_id:         account.id,
      account_name:       account.name,
      account_user_count: account.users.count
    }

    account.users.each do |user|
      analytics_client.request({
        type:  data[:type],
        id:    user.id,
        email: user.email
      }.merge(account_attributes))
    end
  rescue e
    raise ConnectionFailureException.new(e.message)
  end
end

RequestToAnalyticsService.new.perform(args)

After

# your cool code

みんなのコメント

withdrawn_user_1066
Sat, 12 Dec 2015 11:47:22 +0900 投稿
sue445
Wed, 23 Dec 2015 22:44:02 +0900 投稿