Class: YARD::Parser::Rustdoc::Statements::Struct

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#comments_hash_flag, #comments_range, #docstring, #file, #line, #line_range, #show, #source

Constructor Details

#initialize(rustdoc, methods) ⇒ Struct

Returns a new instance of Struct.



67
68
69
70
# File 'lib/yard-rustdoc/statements.rb', line 67

def initialize(rustdoc, methods)
  super(rustdoc)
  @methods = methods
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



65
66
67
# File 'lib/yard-rustdoc/statements.rb', line 65

def methods
  @methods
end

Instance Method Details

#code_object_classObject



88
89
90
91
92
93
94
# File 'lib/yard-rustdoc/statements.rb', line 88

def code_object_class
  if rust_docstring.match?(/^@module\b/)
    YARD::CodeObjects::ModuleObject
  else
    YARD::CodeObjects::ClassObject
  end
end

#nameObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/yard-rustdoc/statements.rb', line 72

def name
  return $1.strip if docstring =~ /^@rename\s*(.+)/

  @rustdoc["attrs"].each do |attr|
    next unless attr.include?("magnus")

    # Extract class name from magnus attrs that define classes such as:
    #   - #[magnus::wrap(class = "ClassName")]
    #   - #[magnus(class = "ClassName")]
    return $1.strip if attr =~ /class\s*=\s*"([^"]+)"/
  end

  # Fallback to the struct's name
  @rustdoc.fetch("name")
end