lib/yard/serializers/yardoc_serializer.rb in yard-0.9.4 vs lib/yard/serializers/yardoc_serializer.rb in yard-0.9.5
- old
+ new
@@ -34,9 +34,32 @@
def objects_path; File.join(basepath, 'objects') end
# @deprecated The registry no longer tracks proxy types
def proxy_types_path; File.join(basepath, 'proxy_types') end
def checksums_path; File.join(basepath, 'checksums') end
def object_types_path; File.join(basepath, 'object_types') end
+ def complete_lock_path; File.join(basepath, 'complete') end
+ def processing_path; File.join(basepath, 'processing') end
+
+ def complete?
+ File.exist?(complete_lock_path) && !locked_for_writing?
+ end
+
+ # Creates a pessmistic transactional lock on the database for writing.
+ # Use with {YARD.parse} to ensure the database is not written multiple
+ # times.
+ #
+ # @see #locked_for_writing?
+ def lock_for_writing(&block)
+ File.open!(processing_path, 'w') {}
+ yield
+ ensure
+ File.unlink(processing_path) if File.exist?(processing_path)
+ end
+
+ # @return [Boolean] whether the database is currently locked for writing
+ def locked_for_writing?
+ File.exist?(processing_path)
+ end
def serialized_path(object)
path = case object
when String, Symbol
object = object.to_s
\ No newline at end of file