Class: YARD::Serializers::FileSystemSerializer
- Defined in:
- lib/yard/serializers/file_system_serializer.rb
Overview
Implements a serializer that reads from and writes to the filesystem.
Direct Known Subclasses
Instance Attribute Summary collapse
- 
  
    
      #basepath  ⇒ String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The base path to write data to. 
- 
  
    
      #extension  ⇒ String 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    The extension of the filename (defaults to html).
Instance Method Summary collapse
- 
  
    
      #exists?(object)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Checks the disk for an object and returns whether it was serialized. 
- 
  
    
      #initialize(opts = {})  ⇒ FileSystemSerializer 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Creates a new FileSystemSerializer with options. 
- 
  
    
      #serialize(object, data)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Serializes object with data to its serialized path (prefixed by the #basepath).
- 
  
    
      #serialized_path(object)  ⇒ String 
    
    
  
  
  
  
  
  
  
  
  
    Implements the serialized path of a code object. 
Constructor Details
#initialize(opts = {}) ⇒ FileSystemSerializer
Creates a new FileSystemSerializer with options
| 28 29 30 31 32 33 | # File 'lib/yard/serializers/file_system_serializer.rb', line 28 def initialize(opts = {}) super @name_map = nil @basepath = ([:basepath] || 'doc').to_s @extension = (.key?(:extension) ? [:extension] : 'html').to_s end | 
Instance Attribute Details
#basepath ⇒ String
The base path to write data to.
| 8 9 10 | # File 'lib/yard/serializers/file_system_serializer.rb', line 8 def basepath @basepath end | 
#extension ⇒ String
The extension of the filename (defaults to html)
| 17 18 19 | # File 'lib/yard/serializers/file_system_serializer.rb', line 17 def extension @extension end | 
Instance Method Details
#exists?(object) ⇒ Boolean
Checks the disk for an object and returns whether it was serialized.
| 71 72 73 | # File 'lib/yard/serializers/file_system_serializer.rb', line 71 def exists?(object) File.exist?(File.join(basepath, serialized_path(object))) end | 
#serialize(object, data) ⇒ String
Serializes object with data to its serialized path (prefixed by the #basepath).
| 38 39 40 41 42 | # File 'lib/yard/serializers/file_system_serializer.rb', line 38 def serialize(object, data) path = File.join(basepath, serialized_path(object)) log.debug "Serializing to #{path}" File.open!(path, "wb") {|f| f.write data } end | 
#serialized_path(object) ⇒ String
Implements the serialized path of a code object.
| 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | # File 'lib/yard/serializers/file_system_serializer.rb', line 50 def serialized_path(object) return object if object.is_a?(String) if object.is_a?(CodeObjects::ExtraFileObject) fspath = ['file.' + object.name + (extension.empty? ? '' : ".#{extension}")] else objname = object != YARD::Registry.root ? mapped_name(object) : "top-level-namespace" objname += '_' + object.scope.to_s[0, 1] if object.is_a?(CodeObjects::MethodObject) fspath = [objname + (extension.empty? ? '' : ".#{extension}")] if object.namespace && object.namespace.path != "" fspath.unshift(*object.namespace.path.split(CodeObjects::NSEP)) end end File.join(encode_path_components(*fspath)) end |