File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -17,4 +17,26 @@ namespace :kpi do
17
17
end
18
18
end
19
19
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
20
42
end
You can’t perform that action at this time.
0 commit comments