123456789_123456789_123456789_123456789_123456789_

Class: YARD::Serializers::YardocSerializer

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: YARD::Serializers::FileSystemSerializer
Defined in: lib/yard/serializers/yardoc_serializer.rb

Class Method Summary

FileSystemSerializer - Inherited

.new

Creates a new FileSystemSerializer with options.

Base - Inherited

.new

Creates a new serializer with options.

Instance Attribute Summary

FileSystemSerializer - Inherited

#basepath

The base path to write data to.

#basepath=,
#extension

The extension of the filename (defaults to html).

#extension=

Base - Inherited

#options

All serializer options are saved so they can be passed to other serializers.

Instance Method Summary

FileSystemSerializer - Inherited

#exists?

Checks the disk for an object and returns whether it was serialized.

#serialize

Serializes object with data to its serialized path (prefixed by the #basepath).

#serialized_path

Implements the serialized path of a code object.

#build_filename_map

Builds a filename mapping from object paths to filesystem path names.

#encode_path_components

Remove special chars from filenames.

#mapped_name

Base - Inherited

#after_serialize

Called after serialization.

#before_serialize

Called before serialization.

#exists?

Returns whether an object has been serialized.

#serialize

Serializes an object.

#serialized_path

The serialized path of an object.

Constructor Details

.new(yfile) ⇒ YardocSerializer

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 33

def initialize(yfile)
  super(:basepath => yfile, :extension => 'dat')
end

Instance Attribute Details

#complete?Boolean (readonly)

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 45

def complete?
  File.exist?(complete_lock_path) && !locked_for_writing?
end

#locked_for_writing?Boolean (readonly)

Returns:

  • (Boolean)

    whether the database is currently locked for writing

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 62

def locked_for_writing?
  File.exist?(processing_path)
end

Instance Method Details

#checksums_path

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 40

def checksums_path; File.join(basepath, 'checksums') end

#complete_lock_path

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 42

def complete_lock_path; File.join(basepath, 'complete') end

#deserialize(path, is_path = false)

[ GitHub ]

  
# 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

#dump(object) (private)

[ GitHub ]

  
# 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) (private)

[ GitHub ]

  
# 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

#lock_for_writing

Creates a pessmistic transactional lock on the database for writing. Use with YARD.parse to ensure the database is not written multiple times.

[ GitHub ]

  
# 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

#object_types_path

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 41

def object_types_path; File.join(basepath, 'object_types') end

#objects_path

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 37

def objects_path; File.join(basepath, 'objects') end

#processing_path

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 43

def processing_path; File.join(basepath, 'processing') end

#proxy_types_path

Deprecated.

The registry no longer tracks proxy types

[ GitHub ]

  
# File 'lib/yard/serializers/yardoc_serializer.rb', line 39

def proxy_types_path; File.join(basepath, 'proxy_types') end

#serialize(object)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# 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