Class: YARD::Serializers::FileSystemSerializer
- Inherits:
-
Base
- Object
- Base
- YARD::Serializers::FileSystemSerializer
- Defined in:
- lib/yard/serializers/file_system_serializer.rb
Instance Attribute Summary
- - (String) basepath readonly The base path to write data to.
- - (String) extension readonly The extension of the filename (defaults to html).
Instance Method Summary
- - (FileSystemSerializer) initialize(opts = {}) constructor Creates a new FileSystemSerializer with options.
- - (String) serialize(object, data) Serializes object with data to its serialized path (prefixed by the #basepath).
- - (String) serialized_path(object) Implements the serialized path of a code object.
Methods inherited from Base
#after_serialize, #before_serialize
Constructor Details
- (FileSystemSerializer) initialize(opts = {})
Creates a new FileSystemSerializer with options
18 19 20 21 22 |
# File 'lib/yard/serializers/file_system_serializer.rb', line 18 def initialize(opts = {}) super @basepath = ([:basepath] || 'doc').to_s @extension = (.has_key?(:extension) ? [:extension] : 'html').to_s end |
Instance Attribute Details
- (String) basepath (readonly)
The base path to write data to.
6 7 8 |
# File 'lib/yard/serializers/file_system_serializer.rb', line 6 def basepath @basepath end |
- (String) extension (readonly)
The extension of the filename (defaults to html)
11 12 13 |
# File 'lib/yard/serializers/file_system_serializer.rb', line 11 def extension @extension end |
Instance Method Details
- (String) serialize(object, data)
Serializes object with data to its serialized path (prefixed by the #basepath).
27 28 29 30 31 |
# File 'lib/yard/serializers/file_system_serializer.rb', line 27 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 |
- (String) serialized_path(object)
Implements the serialized path of a code object.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/yard/serializers/file_system_serializer.rb', line 39 def serialized_path(object) return object if object.is_a?(String) objname = object != YARD::Registry.root ? object.name.to_s : "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 # Don't change the filenames, it just makes it more complicated # to figure out the original name. #fspath.map! do |p| # p.gsub(/([a-z])([A-Z])/, '\1_\2').downcase #end # Remove special chars from filenames. # Windows disallows \ / : * ? " < > | but we will just remove any # non alphanumeric (plus period, underscore and dash). fspath.map! do |p| p.gsub(/[^\w\.-]/) do |x| encoded = '_' x.each_byte { |b| encoded << ("%X" % b) } encoded end end File.join(fspath) end |