lib/lookbook/parser.rb in lookbook-1.0.4 vs lib/lookbook/parser.rb in lookbook-1.0.5

- old
+ new

@@ -1,27 +1,35 @@ require "yard" module Lookbook class Parser attr_reader :registry_path - def initialize(paths, registry_path) + def initialize(paths) @paths = paths.map { |p| "#{p}/**/*preview.rb" } - @registry_path = registry_path.to_s - YARD::Registry.yardoc_file = registry_path + @after_parse_callbacks = [] + @after_parse_once_callbacks = [] + @parsing = false + + YARD::Parser::SourceParser.after_parse_list do + [*@after_parse_callbacks, *@after_parse_once_callbacks].each do |callback| + callback.call(YARD::Registry) + end + @after_parse_once_callbacks = [] + @parsing = false + end end - def parse - YARD::Registry.clear - YARD::Registry.lock_for_writing do + def parse(&block) + unless @parsing + @parsing = true + @after_parse_once_callbacks << block if block + YARD::Registry.clear YARD.parse(@paths) - YARD::Registry.save(false, registry_path) end end - def get_code_object(path) - registry = YARD::RegistryStore.new - registry.load!(registry_path) - registry.get(path) + def after_parse(&block) + @after_parse_callbacks << block end class << self def define_tags(custom = {}) YARD::Tags::Library.define_tag("Hidden status", :hidden)