# Class: YARD::Serializers::YardocSerializer

Inherits:
  FileSystemSerializer
  - Object
  - Base
  - FileSystemSerializer
  - YARD::Serializers::YardocSerializer
  show all

Defined in:
  lib/yard/serializers/yardoc_serializer.rb

## Instance Method Summary collapse

- #checksums_path ⇒ Object
- #complete? ⇒ Boolean
- #complete_lock_path ⇒ Object
- #deserialize(path, is_path = false) ⇒ Object
- #initialize(yfile) ⇒ YardocSerializer constructor

  A new instance of YardocSerializer.

- #lock_for_writing ⇒ Object

  Creates a pessmistic transactional lock on the database for writing.

- #locked_for_writing? ⇒ Boolean

  Whether the database is currently locked for writing.

- #object_types_path ⇒ Object
- #objects_path ⇒ Object
- #processing_path ⇒ Object
- #proxy_types_path ⇒ Object deprecated Deprecated.

  The registry no longer tracks proxy types

- #serialize(object) ⇒ Object
- #serialized_path(object) ⇒ Object

## Constructor Details

### #initialize(yfile) ⇒ `YardocSerializer`

Returns a new instance of YardocSerializer.

    33
    34
    35

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

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

## Instance Method Details

### #checksums_path ⇒ `Object`

    40

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

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

### #complete? ⇒ `Boolean`

Returns:

- (`Boolean`)

    45
    46
    47

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

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

### #complete_lock_path ⇒ `Object`

    42

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

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

### #deserialize(path, is_path = false) ⇒ `Object`

    101
    102
    103
    104
    105
    106
    107
    108
    109
    110

    # 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 ⇒ `Object`

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

See Also:

- #locked_for_writing?

    54
    55
    56
    57
    58
    59

    # 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? ⇒ `Boolean`

Returns whether the database is currently locked for writing.

Returns:

- (`Boolean`) —

  whether the database is currently locked for writing

    62
    63
    64

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

    def locked_for_writing?
      File.exist?(processing_path)
    end

### #object_types_path ⇒ `Object`

    41

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

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

### #objects_path ⇒ `Object`

    37

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

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

### #processing_path ⇒ `Object`

    43

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

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

### #proxy_types_path ⇒ `Object`

Deprecated.

The registry no longer tracks proxy types

    39

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

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

### #serialize(object) ⇒ `Object`

    93
    94
    95
    96
    97
    98
    99

    # 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) ⇒ `Object`

    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91

    # 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