class YARD::Serializers::FileSystemSerializer
Implements a serializer that reads from and writes to the filesystem.
def basepath=(value)
def basepath=(value) @basepath = options[:basepath] = value end
def build_filename_map
- Note: - In order to use filesystem name mapping, you must initialize
def build_filename_map @name_map = {} YARD::Registry.all.each do |object| lpath = nil if object.parent && object.parent.type != :root lpath = object.parent.path + "::" + object.name.to_s.downcase else lpath = object.path.downcase end @name_map[lpath] ||= {} size = @name_map[lpath].size name = "#{object.name}#{size > 0 ? "_" * size : ""}" @name_map[lpath][object.name] = name end end
def encode_path_components(*components)
Windows disallows \ / : * ? " < > | but we will just remove any
Remove special chars from filenames.
def encode_path_components(*components) components.map! do |p| p.gsub(/[^\w\.-]/) do |x| encoded = String.new('_') x.each_byte {|b| encoded << ("%X" % b) } encoded end end end
def exists?(object)
-
(Boolean)
- whether an object has been serialized to disk
Parameters:
-
object
(CodeObjects::Base
) -- the object to check
def exists?(object) File.exist?(File.join(basepath, serialized_path(object))) end
def extension=(value)
def extension=(value) @extension = options[:extension] = value end
def initialize(opts = {})
(**opts)
-
:extension
(String
) -- the extension of the serialized -
:basepath
(String
) -- the base path to write data to
def initialize(opts = {}) super @name_map = nil @basepath = (options[:basepath] || 'doc').to_s @extension = (options.key?(:extension) ? options[:extension] : 'html').to_s end
def mapped_name(object)
-
(String)
- the filesystem mapped name of a given object.
def mapped_name(object) build_filename_map unless @name_map map = @name_map[object.path.downcase] map && map[object.name] ? map[object.name] : object.name.to_s end
def serialize(object, data)
-
(String)
- the written data (for chaining)
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
def serialized_path(object)
-
(String)
- if object is a String, returns
Parameters:
-
object
(CodeObjects::Base, CodeObjects::ExtraFileObject, String
) --
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