class YARD::Serializers::YardocSerializer

Public Class Methods

new(yfile) click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 33
def initialize(yfile)
  super(:basepath => yfile, :extension => 'dat')
end

Public Instance Methods

checksums_path() click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 40
def checksums_path; File.join(basepath, 'checksums') end
complete?() click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 45
def complete?
  File.exist?(complete_lock_path) && !locked_for_writing?
end
complete_lock_path() click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 42
def complete_lock_path; File.join(basepath, 'complete') end
deserialize(path, is_path = false) click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 101
def deserialize(path, is_path = false)
  path = File.join(basepath, serialized_path(path)) unless is_path
  if File.file?(path)
    log.debug "Deserializing #{path}..."
    Marshal.load(File.read_binary(path))
  else
    log.debug "Could not find #{path}"
    nil
  end
end
lock_for_writing() { || ... } click to toggle source

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?

# File lib/yard/serializers/yardoc_serializer.rb, line 54
def lock_for_writing
  File.open!(processing_path, 'w') {}
  yield
ensure
  File.unlink(processing_path) if File.exist?(processing_path)
end
locked_for_writing?() click to toggle source

@return [Boolean] whether the database is currently locked for writing

# File lib/yard/serializers/yardoc_serializer.rb, line 62
def locked_for_writing?
  File.exist?(processing_path)
end
object_types_path() click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 41
def object_types_path; File.join(basepath, 'object_types') end
objects_path() click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 37
def objects_path; File.join(basepath, 'objects') end
processing_path() click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 43
def processing_path; File.join(basepath, 'processing') end
proxy_types_path() click to toggle source

@deprecated The registry no longer tracks proxy types

# File lib/yard/serializers/yardoc_serializer.rb, line 39
def proxy_types_path; File.join(basepath, 'proxy_types') end
serialize(object) click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 93
def serialize(object)
  if Hash === object
    super(object[:root], dump(object)) if object[:root]
  else
    super(object, dump(object))
  end
end
serialized_path(object) click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 66
def serialized_path(object)
  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

  File.join('objects', path)
end

Private Instance Methods

dump(object) click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 114
def dump(object)
  object = internal_dump(object, true) unless object.is_a?(Hash)
  Marshal.dump(object)
end
internal_dump(object, first_object = false) click to toggle source
# File lib/yard/serializers/yardoc_serializer.rb, line 119
def internal_dump(object, first_object = false)
  if !first_object && object.is_a?(CodeObjects::Base) &&
     !(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.empty?
    object = object.dup
  end

  object.instance_variables.each do |ivar|
    ivar_obj = object.instance_variable_get(ivar)
    ivar_obj_dump = internal_dump(ivar_obj)
    object.instance_variable_set(ivar, ivar_obj_dump)
  end

  case object
  when Hash
    list = object.map do |k, v|
      [k, v].map {|item| internal_dump(item) }
    end
    object.replace(Hash[list])
  when Array
    list = object.map {|item| internal_dump(item) }
    object.replace(list)
  end

  object
end