-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide rake task to integrate multiple method_call_situations records …
- Loading branch information
1 parent
79ccce7
commit c329d31
Showing
3 changed files
with
24 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,21 @@ | ||
# desc "Explaining what the task does" | ||
# task :okuribito_rails do | ||
# # Task goes here | ||
# end | ||
namespace :okuribito_rails do | ||
desc "Integrate multiple method_call_situations records" | ||
task integrate_method_call_situations: :environment do | ||
puts "Integrate multiple method_call_situations records...." | ||
|
||
OkuribitoRails::MethodCallSituation.group_by_method.each do |situation| | ||
puts "#{situation.class_name}#{situation.method_symbol}#{situation.method_name}" | ||
situations = OkuribitoRails::MethodCallSituation.where(class_name: situation.class_name, | ||
method_symbol: situation.method_symbol, | ||
method_name: situation.method_name) | ||
if situations.size > 1 | ||
sum = situations.pluck(:called_num).inject(0) { |a, e| a + e } | ||
situations[0].update(called_num: sum) | ||
situations[1..-1].each(&:destroy) | ||
puts " integrate #{situations.size} records..." | ||
else | ||
puts " nothing to do..." | ||
end | ||
end | ||
end | ||
end |