Created
October 20, 2015 20:30
-
-
Save lsegal/00968a764bc5e91e5ac2 to your computer and use it in GitHub Desktop.
YARD plugin to handle filename case map collisions on case insensitive filesystems.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileSystemSerializerNoCase < YARD::Serializers::FileSystemSerializer | |
def initialize(opts = {}) | |
super(opts) | |
build_name_map | |
end | |
def serialized_path(object) | |
path = super(object) | |
if object.is_a?(YARD::CodeObjects::NamespaceObject) && object.type != :root | |
if repl = @name_map[object.path.downcase][object.name] | |
base, fname = *File.split(path) | |
fname = fname.sub(/^(.+)\.#{extension}$/, "#{repl}.#{extension}") | |
path = File.join(base, fname) | |
end | |
end | |
path | |
end | |
private | |
def build_name_map | |
@name_map = {} | |
YARD::Registry.all.each do |object| | |
lpath = object.name.to_s.downcase | |
@name_map[lpath] ||= {} | |
@name_map[lpath][object.name] = object.name.to_s | |
size = @name_map[lpath].size | |
@name_map[lpath][object.name] += size.to_s if size > 1 | |
end | |
end | |
end | |
module ReplaceSerializer | |
def generate(objects, options) | |
options.serializer = FileSystemSerializerNoCase.new( | |
basepath: options.serializer.basepath, | |
extension: options.serializer.extension | |
) | |
super(objects, options) | |
end | |
end | |
module YARD::Templates::Engine | |
class << self | |
prepend ReplaceSerializer | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment