lib/orthoses/yard.rb in orthoses-yard-0.1.0 vs lib/orthoses/yard.rb in orthoses-yard-0.2.0
- old
+ new
@@ -2,31 +2,31 @@
require 'orthoses'
require_relative "yard/version"
require_relative "yard/yard2rbs"
module Orthoses
- # use Orthoses::YARD, globs: "lib/**/*.rb"
+ # use Orthoses::YARD, parse: "lib/**/*.rb"
class YARD
- def initialize(loader, globs:)
+ def initialize(loader, parse:)
@loader = loader
- @globs = Array(globs)
+ @parse = Array(parse)
end
def call
@loader.call.tap do |store|
require 'yard'
- ::YARD.parse(@globs)
+ ::YARD.parse(@parse)
::YARD::Registry.root.children.each do |yardoc|
case yardoc.type
when :class, :module
YARD2RBS.run(yardoc: yardoc) do |namespace, docstring, rbs|
+ comment = docstring.each_line.map { |line| "# #{line}" }.join
if rbs.nil?
- store[namespace]
+ store[namespace].comment = comment
else
Orthoses.logger.debug("#{namespace} << #{rbs}")
- all = docstring.all.then { |it| it.empty? ? "" : "#{it.gsub(/^/, '# ')}\n" }
- store[namespace] << "#{all}#{rbs}"
+ store[namespace] << "#{comment}\n#{rbs}"
end
end
end
end
end