lib/steep/drivers/scaffold.rb in steep-0.2.0 vs lib/steep/drivers/scaffold.rb in steep-0.3.0
- old
+ new
@@ -43,10 +43,16 @@
end
def module?
kind == :module
end
+
+ attr_accessor :has_subclass
+
+ def namespace_class?
+ has_subclass && methods.empty? && singleton_methods.empty?
+ end
end
attr_reader :source
attr_reader :modules
attr_reader :constants
@@ -61,11 +67,11 @@
def write(io:)
generate(source.node, current_path: [])
modules.each do |mod|
- unless mod.methods.empty? && mod.singleton_methods.empty?
+ unless mod.namespace_class?
io.puts "#{mod.kind} #{mod.name}"
mod.ivars.each do |name, type|
io.puts " #{name}: #{type}"
end
@@ -117,18 +123,26 @@
generate(node.children[1],
current_path: current_path + [name],
current_module: mod)
end
+ if current_module
+ current_module.has_subclass = true
+ end
+
when :class
name = module_name(node.children[0])
klass = Module.new(name: full_name(current_path, name), kind: :class)
modules << klass
if node.children[2]
generate(node.children[2],
current_path: current_path + [name],
current_module: klass)
+ end
+
+ if current_module
+ current_module.has_subclass = true
end
when :def
name, args, body = node.children