Class: YARD::CodeObjects::NotesFileObject
- Inherits:
-
ExtraFileObject
- Object
- ExtraFileObject
- YARD::CodeObjects::NotesFileObject
- Defined in:
- lib/yard-notes.rb
Instance Method Summary collapse
-
#contents ⇒ Object
Lazily produce contents.
-
#initialize ⇒ NotesFileObject
constructor
A new instance of NotesFileObject.
-
#parse_contents(data) ⇒ String
This method was taken directly from YARD and change by removing ‘self.` from `contents`, so that it can be lazily created.
Constructor Details
#initialize ⇒ NotesFileObject
Returns a new instance of NotesFileObject.
51 52 53 54 55 |
# File 'lib/yard-notes.rb', line 51 def initialize self.filename = 'NOTES.md' self.name = 'NOTES' self.attributes = SymbolHash.new(false) end |
Instance Method Details
#contents ⇒ Object
Lazily produce contents.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/yard-notes.rb', line 58 def contents @contents ||= ( text = ["# Developer's Notes"] sort = Hash.new{ |h,k| h[k] = [] } = Tags::Library. Registry.each do |code_object| code_object..each do |tag| next unless .include?(tag.tag_name) sort[tag.tag_name] << tag end end sort.each do |name, | text << "## #{name}" .each do |tag| text << "* #{tag.text} (#{tag.object})" end end parse_contents(text.join("\n\n")) ) end |
#parse_contents(data) ⇒ String
This method was taken directly from YARD and change by removing ‘self.` from `contents`, so that it can be lazily created.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/yard-notes.rb', line 89 def parse_contents(data) retried = false cut_index = 0 data = data.split("\n") data.each_with_index do |line, index| case line when /^#!(\S+)\s*$/ if index == 0 attributes[:markup] = $1 else cut_index = index break end when /^\s*#\s*@(\S+)\s*(.+?)\s*$/ attributes[$1] = $2 else cut_index = index break end end data = data[cut_index..-1] if cut_index > 0 contents = data.join("\n") if contents.respond_to?(:force_encoding) && attributes[:encoding] begin contents.force_encoding(attributes[:encoding]) rescue ArgumentError log.warn "Invalid encoding `#{attributes[:encoding]}' in #{filename}" end end return contents rescue ArgumentError => e if retried && e. =~ /invalid byte sequence/ # This should never happen. log.warn "Could not read #{filename}, #{e.}. You probably want to set `--charset`." contents = '' return end data.force_encoding('binary') if data.respond_to?(:force_encoding) retried = true retry end |