File tree Expand file tree Collapse file tree 5 files changed +37
-1
lines changed Expand file tree Collapse file tree 5 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ warn: true
6060title: sample title
6161exclude: null
6262only: null
63+ only_recursion_depth: null
6364prepend_primary: false
6465cluster: false
6566```
Original file line number Diff line number Diff line change @@ -17,5 +17,6 @@ warn: true
1717title: sample title
1818exclude: null
1919only: null
20+ only_recursion_depth: null
2021prepend_primary: false
2122cluster: false
Original file line number Diff line number Diff line change @@ -51,8 +51,9 @@ def default_options
5151 :title , true ,
5252 :exclude , nil ,
5353 :only , nil ,
54+ :only_recursion_depth , nil ,
5455 :prepend_primary , false ,
55- :cluster , false
56+ :cluster , false ,
5657 ]
5758 end
5859 end
Original file line number Diff line number Diff line change 4949 desc "Filter to only include listed models in diagram."
5050 end
5151
52+ option :only_recursion_depth do
53+ long "--only_recursion_depth=INTEGER"
54+ desc "Recurses into relations specified by --only upto a depth N."
55+ end
56+
5257 option :exclude do
5358 long "--exclude"
5459 desc "Filter to exclude listed models in diagram."
Original file line number Diff line number Diff line change @@ -125,6 +125,14 @@ def create
125125 def generate
126126 instance_eval ( &callbacks [ :setup ] )
127127
128+ if options . only_recursion_depth . present?
129+ depth = options . only_recursion_depth . to_i
130+ options . only . dup . each do |class_name |
131+ options . only += recurse_into_relationships ( @domain . entity_by_name ( class_name ) , depth )
132+ end
133+ options . only . uniq!
134+ end
135+
128136 filtered_entities . each do |entity |
129137 instance_exec entity , filtered_attributes ( entity ) , &callbacks [ :each_entity ]
130138 end
@@ -138,6 +146,26 @@ def generate
138146 end
139147 end
140148
149+ def recurse_into_relationships ( entity , max_level , current_level = 0 )
150+ return [ ] unless entity
151+ return [ ] if max_level == current_level
152+
153+ relationships = entity . relationships . reject { |r | r . indirect? || r . recursive? }
154+
155+ relationships . map do |relationship |
156+ other_entitiy = if relationship . source == entity
157+ relationship . destination
158+ else
159+ relationship . source
160+ end
161+ if other_entitiy and !other_entitiy . generalized?
162+ [ other_entitiy . name ] + recurse_into_relationships ( other_entitiy , max_level , current_level + 1 )
163+ else
164+ [ ]
165+ end
166+ end . flatten . uniq
167+ end
168+
141169 def save
142170 instance_eval ( &callbacks [ :save ] )
143171 end
You can’t perform that action at this time.
0 commit comments