@@ -85,16 +85,18 @@ def initialize(type_name:, library_options:, after_path: [], before_path: [])
8585 def each_diff ( &block )
8686 return to_enum ( :each_diff ) unless block
8787
88- before_instance_methods , before_singleton_methods = build_methods ( @before_path )
89- after_instance_methods , after_singleton_methods = build_methods ( @after_path )
88+ before_instance_methods , before_singleton_methods , before_constant_decls = build_methods ( @before_path )
89+ after_instance_methods , after_singleton_methods , after_constant_decls = build_methods ( @after_path )
9090
91- each_diff_by ( :instance , before_instance_methods , after_instance_methods , &block )
92- each_diff_by ( :singleton , before_singleton_methods , after_singleton_methods , &block )
91+ each_diff_methods ( :instance , before_instance_methods , after_instance_methods , &block )
92+ each_diff_methods ( :singleton , before_singleton_methods , after_singleton_methods , &block )
93+
94+ each_diff_constants ( before_constant_decls , after_constant_decls , &block )
9395 end
9496
9597 private
9698
97- def each_diff_by ( kind , before_methods , after_methods )
99+ def each_diff_methods ( kind , before_methods , after_methods )
98100 all_keys = before_methods . keys . to_set + after_methods . keys . to_set
99101 all_keys . each do |key |
100102 before = definition_method_to_s ( key , kind , before_methods [ key ] ) or next
@@ -105,6 +107,17 @@ def each_diff_by(kind, before_methods, after_methods)
105107 end
106108 end
107109
110+ def each_diff_constants ( before_constant_decls , after_constant_decls )
111+ all_keys = before_constant_decls . keys . to_set + after_constant_decls . keys . to_set
112+ all_keys . each do |key |
113+ before = constant_to_s ( key , before_constant_decls [ key ] ) or next
114+ after = constant_to_s ( key , after_constant_decls [ key ] ) or next
115+ next if before == after
116+
117+ yield before , after
118+ end
119+ end
120+
108121 def build_methods ( path )
109122 env = build_env ( path )
110123 builder = build_builder ( env )
@@ -121,8 +134,10 @@ def build_methods(path)
121134 RBS . logger . warn ( "#{ path } : #{ e . message } " )
122135 { }
123136 end
137+ type_name_to_s = @type_name . to_s
138+ constant_decls = env . constant_decls . select { |key | key . to_s . start_with? ( type_name_to_s ) }
124139
125- [ instance_methods , singleton_methods ]
140+ [ instance_methods , singleton_methods , constant_decls ]
126141 end
127142
128143 def build_env ( path )
@@ -147,7 +162,15 @@ def definition_method_to_s(key, kind, definition_method)
147162 "def #{ prefix } #{ key } : #{ definition_method . method_types . join ( " | " ) } "
148163 end
149164 else
150- +"-"
165+ "-"
166+ end
167+ end
168+
169+ def constant_to_s ( key , constant )
170+ if constant
171+ "#{ key } : #{ constant . decl . type } "
172+ else
173+ "-"
151174 end
152175 end
153176 end
0 commit comments