lib/yard/serializers/yardoc_serializer.rb in yard-0.9.5 vs lib/yard/serializers/yardoc_serializer.rb in yard-0.9.6
- old
+ new
@@ -1,13 +1,14 @@
+# frozen_string_literal: true
module YARD
# Stubs marshal dumps and acts a delegate class for an object by path
#
# @private
class StubProxy
instance_methods.each {|m| undef_method(m) unless m.to_s =~ /^__|^object_id$/ }
- def _dump(depth) @path end
+ def _dump(_depth) @path end
def self._load(str) new(str) end
def hash; @path.hash end
def initialize(path, transient = false)
@path = path
@@ -18,13 +19,15 @@
return true if meth == :respond_to? && args.first == :_dump
@object = nil if @transient
@object ||= Registry.at(@path)
@object.send(meth, *args, &block)
rescue NoMethodError => e
- e.backtrace.delete_if {|l| l[0, __FILE__.size] == __FILE__ }
+ e.backtrace.delete_if {|l| l[0, FILELEN] == __FILE__ }
raise
end
+
+ FILELEN = __FILE__.size
end
module Serializers
class YardocSerializer < FileSystemSerializer
def initialize(yfile)
@@ -46,11 +49,11 @@
# 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)
+ def lock_for_writing
File.open!(processing_path, 'w') {}
yield
ensure
File.unlink(processing_path) if File.exist?(processing_path)
end
@@ -59,31 +62,33 @@
def locked_for_writing?
File.exist?(processing_path)
end
def serialized_path(object)
- path = case object
- when String, Symbol
- object = object.to_s
- if object =~ /#/
- object += '_i'
- elsif object =~ /\./
- object += '_c'
+ path =
+ case object
+ when String, Symbol
+ object = object.to_s
+ if object =~ /#/
+ object += '_i'
+ elsif object =~ /\./
+ object += '_c'
+ end
+ object.split(/::|\.|#/).map do |p|
+ p.gsub(/[^\w\.-]/) do |x|
+ encoded = '_'
+
+ x.each_byte {|b| encoded << ("%X" % b) }
+ encoded
+ end
+ end.join('/') + '.' + extension
+ when YARD::CodeObjects::RootObject
+ 'root.dat'
+ else
+ super(object)
end
- object.split(/::|\.|#/).map do |p|
- p.gsub(/[^\w\.-]/) do |x|
- encoded = '_'
- x.each_byte { |b| encoded << ("%X" % b) }
- encoded
- end
- end.join('/') + '.' + extension
- when YARD::CodeObjects::RootObject
- 'root.dat'
- else
- super(object)
- end
File.join('objects', path)
end
def serialize(object)
if Hash === object
@@ -111,17 +116,17 @@
Marshal.dump(object)
end
def internal_dump(object, first_object = false)
if !first_object && object.is_a?(CodeObjects::Base) &&
- !(Tags::OverloadTag === object)
+ !(Tags::OverloadTag === object)
return StubProxy.new(object.path)
end
if object.is_a?(Hash) || object.is_a?(Array) ||
- object.is_a?(CodeObjects::Base) ||
- object.instance_variables.size > 0
+ object.is_a?(CodeObjects::Base) ||
+ !object.instance_variables.empty?
object = object.dup
end
object.instance_variables.each do |ivar|
ivar_obj = object.instance_variable_get(ivar)
@@ -142,6 +147,6 @@
object
end
end
end
-end
\ No newline at end of file
+end