Class: Decode::Definition

Inherits:
Symbol
  • Object
show all
Defined in:
lib/decode/definition.rb

Overview

A symbol with attached documentation.

Instance Attribute Summary collapse

Attributes inherited from Symbol

#kind, #language, #name, #parent

Instance Method Summary collapse

Methods inherited from Symbol

#inspect, #key, #lexical_path, #path, #qualified_name

Constructor Details

#initialize(kind, name, comments, **options) ⇒ Definition

Returns a new instance of Definition.



26
27
28
29
30
31
# File 'lib/decode/definition.rb', line 26

def initialize(kind, name, comments, **options)
  super(kind, name, **options)
  
  @comments = comments
  @documentation = nil
end

Instance Attribute Details

#commentsObject (readonly)

The comment lines which directly preceeded the definition.



35
36
37
# File 'lib/decode/definition.rb', line 35

def comments
  @comments
end

Instance Method Details

#container?Boolean

Whether this definition can contain nested definitions.

Returns:

  • (Boolean)


76
77
78
# File 'lib/decode/definition.rb', line 76

def container?
  false
end

#documentationDocumentation | Nil

Structured access to the definitions comments.

Returns:

  • (Documentation | Nil)

    A ‘Documentation` if this definition has comments.



90
91
92
93
94
# File 'lib/decode/definition.rb', line 90

def documentation
  if @comments&.any?
    @documentation ||= Documentation.new(@comments)
  end
end

#long_formString | nil

A long form of the definition. e.g. ‘def initialize(kind, name, comments, **options)`.

Returns:

  • (String | nil)


48
49
50
# File 'lib/decode/definition.rb', line 48

def long_form
  self.short_form
end

#multiline?Boolean

Whether the definition spans multiple lines.

Returns:

  • (Boolean)


63
64
65
# File 'lib/decode/definition.rb', line 63

def multiline?
  false
end

#nested?Boolean

Whether this represents a single entity to be documented (along with it’s contents).

Returns:

  • (Boolean)


83
84
85
# File 'lib/decode/definition.rb', line 83

def nested?
  container?
end

#qualified_formString | nil

A long form which uses the qualified name if possible. Defaults to #long_form.

Returns:

  • (String | nil)


56
57
58
# File 'lib/decode/definition.rb', line 56

def qualified_form
  self.long_form
end

#short_formString | nil

A short form of the definition. e.g. ‘def short_form`.

Returns:

  • (String | nil)


41
42
# File 'lib/decode/definition.rb', line 41

def short_form
end

#textString | nil

The full text of the definition.

Returns:

  • (String | nil)


70
71
# File 'lib/decode/definition.rb', line 70

def text
end