Skip to content

Commit 8594f8e

Browse files
committed
rails kpi:print_hierarchy
1 parent b45274d commit 8594f8e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/tasks/kpi.rake

+22
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,26 @@ namespace :kpi do
1717
end
1818
end
1919
end
20+
21+
# Run with paremeters like this:
22+
# INCLUDE_KPIS=true CATEGORY_NAME='Category Name' rails kpi:print_hierarchy
23+
desc "Prints a hierarchy of all categories or a single category, its subcategories, and optionally KPIs"
24+
task :print_hierarchy => :environment do
25+
include_kpis = ENV['INCLUDE_KPIS'] == 'true'
26+
category_name = ENV['CATEGORY_NAME']
27+
28+
categories = category_name ? Category.where(name: category_name) : Category.all
29+
30+
categories.find_each do |category|
31+
puts category.name
32+
category.subcategories.find_each do |subcategory|
33+
puts " #{subcategory.name}"
34+
if include_kpis
35+
subcategory.kpis.find_each do |kpi|
36+
puts " #{kpi.name}"
37+
end
38+
end
39+
end
40+
end
41+
end
2042
end

0 commit comments

Comments
 (0)