Class: YARD::Parser::Rustdoc::Statements::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yard-rustdoc/statements.rb

Direct Known Subclasses

Method, Struct

Instance Method Summary collapse

Constructor Details

#initialize(rustdoc) ⇒ Base

Returns a new instance of Base.



6
7
8
9
10
# File 'lib/yard-rustdoc/statements.rb', line 6

def initialize(rustdoc)
  @rustdoc = rustdoc
  @name = nil
  @parameters = []
end

Instance Method Details

#comments_hash_flagObject

Not sure what should go here either



47
48
# File 'lib/yard-rustdoc/statements.rb', line 47

def comments_hash_flag
end

#comments_rangeObject



50
51
# File 'lib/yard-rustdoc/statements.rb', line 50

def comments_range
end

#docstringObject



12
13
14
15
# File 'lib/yard-rustdoc/statements.rb', line 12

def docstring
  @docstring ||= rust_docstring
    .gsub(/^\s*@yard\s*\n/m, "") # remove @yard line
end

#fileObject



38
39
40
# File 'lib/yard-rustdoc/statements.rb', line 38

def file
  @rustdoc.dig("span", "filename")
end

#lineObject



30
31
32
# File 'lib/yard-rustdoc/statements.rb', line 30

def line
  line_range.first
end

#line_rangeObject



34
35
36
# File 'lib/yard-rustdoc/statements.rb', line 34

def line_range
  @rustdoc.dig("span", "begin", 0)...@rustdoc.dig("span", "end", 0)
end

#showObject



42
43
44
# File 'lib/yard-rustdoc/statements.rb', line 42

def show
  @rustdoc.to_s
end

#sourceObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/yard-rustdoc/statements.rb', line 17

def source
  return if file.nil?

  File.read(file)
    .lines
    .slice(line_index_range)
    .join
rescue Errno::ENOENT
  log.warn("can't read '#{file}', cwd='#{Dir.pwd}'")

  ""
end