Class: Documentation::Base

Inherits:
Treetop::Runtime::SyntaxNode
  • Object
show all
Extended by:
Memoized
Defined in:
lib/pdoc/parser/documentation_nodes.rb

Direct Known Subclasses

Constant, Method, Namespace, Property, Section

Instance Method Summary collapse

Methods included from Memoized

avoid_infinite_method_added_loop, memoize, method_added

Instance Method Details

#alias_ofObject

If instance is tagged as an alias, alias_of returns the corresponding object. It will return nil otherwise.



93
94
95
96
# File 'lib/pdoc/parser/documentation_nodes.rb', line 93

def alias_of
  tag = tags.find { |tag| tag.name == "alias of" }
  tag.value if tag
end

#deprecated?Boolean

True if the instance was tagged as deprecated.

Returns:

  • (Boolean)


87
88
89
# File 'lib/pdoc/parser/documentation_nodes.rb', line 87

def deprecated?
  tags.include?("deprecated")
end

#descriptionObject



156
157
158
# File 'lib/pdoc/parser/documentation_nodes.rb', line 156

def description
  text.to_s
end

#doc_parentObject

If instance is a global, returns its Section. Else its Namespace.



148
149
150
# File 'lib/pdoc/parser/documentation_nodes.rb', line 148

def doc_parent
  namespace ? namespace : section
end

#ebnf_expressionsObject



152
153
154
# File 'lib/pdoc/parser/documentation_nodes.rb', line 152

def ebnf_expressions
  ebnf.elements.map { |e| e.elements.last }
end

#full_nameObject

Returns the instance’s full_name. For example:

root.find_by_name("Element#update").full_name
# -> "Element#update"


123
124
125
# File 'lib/pdoc/parser/documentation_nodes.rb', line 123

def full_name
  ebnf.full_name
end

#inspectObject



164
165
166
# File 'lib/pdoc/parser/documentation_nodes.rb', line 164

def inspect
  "#<#{self.class} #{full_name}>"
end

#klassObject

Returns the Klass instance if object is a class, nil otherwise.



137
138
139
# File 'lib/pdoc/parser/documentation_nodes.rb', line 137

def klass
  nil
end

#klass_nameObject

Returns the instance’s class name.



109
110
111
# File 'lib/pdoc/parser/documentation_nodes.rb', line 109

def klass_name
  ebnf.klass_name
end

#nameObject

Returns the instance’s name. For example:

root.find_by_name("Element#update").name
# -> "update"


116
117
118
# File 'lib/pdoc/parser/documentation_nodes.rb', line 116

def name
  ebnf.name
end

#namespaceObject

Returns the instance’s closests namespace or nil when instance or instance’s Klass is a global.



143
144
145
# File 'lib/pdoc/parser/documentation_nodes.rb', line 143

def namespace
  @namespace ||= namespace_string.empty? ? nil : root.find_by_name(namespace_string)
end

#namespace_stringObject

Returns the instance’s namespace_string. Note that event if the instance is an method or property, the klass_name is not included in that string. So for example:

root.find_by_name("Ajax.Request#request").namespace_string
# -> "Ajax"


132
133
134
# File 'lib/pdoc/parser/documentation_nodes.rb', line 132

def namespace_string
  ebnf.namespace
end

#parent_idObject



172
173
174
# File 'lib/pdoc/parser/documentation_nodes.rb', line 172

def parent_id
  namespace_string.empty? ? section_name : namespace_string
end


98
99
100
101
# File 'lib/pdoc/parser/documentation_nodes.rb', line 98

def related_to
  tag = tags.find { |tag| tag.name == "related to" }
  tag.value if tag
end

#rootObject

Returns an instance of Doc (the root of the tree outputed by the PDoc::Parser).



82
83
84
# File 'lib/pdoc/parser/documentation_nodes.rb', line 82

def root
  parent.parent.parent
end

#section_nameObject



176
177
178
179
180
181
# File 'lib/pdoc/parser/documentation_nodes.rb', line 176

def section_name
  if tags.include?('section')
    value = tags.find { |tag| tag.name == 'section' }.value
    "#{value} section"
  end
end

#serialize(serializer) ⇒ Object



196
197
198
# File 'lib/pdoc/parser/documentation_nodes.rb', line 196

def serialize(serializer)
  serializer << to_yaml
end

#signatureObject



160
161
162
# File 'lib/pdoc/parser/documentation_nodes.rb', line 160

def signature
  ebnf.text_value.strip
end

#src_code_lineObject



168
169
170
# File 'lib/pdoc/parser/documentation_nodes.rb', line 168

def src_code_line
  input.line_of(interval.last) - 1
end

#tagsObject

Returns an instance of Tags::Tags.



104
105
106
# File 'lib/pdoc/parser/documentation_nodes.rb', line 104

def tags
  start.elements.last.empty? ? [] : start.elements.last
end

#to_yamlObject



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/pdoc/parser/documentation_nodes.rb', line 183

def to_yaml
  str = "id: #{full_name.inspect}"
  str << "\nparent_id: #{parent_id.inspect}" if parent_id
  str << "\ntype: #{type}"
  str << "\nsuperclass_id: #{superclass.inspect}" if respond_to?(:superclass) && superclass
  str << "\nincluded: #{mixins.inspect}" if respond_to?(:mixins) && !mixins.empty?
  str << "\nline_number: #{src_code_line}"
  str << "\ndeprecated: true" if deprecated?
  str << "\nalias_of: #{alias_of.inspect}" if respond_to?(:alias_of) && alias_of
  str << "\nrelated_to: #{related_to.inspect}" if respond_to?(:related_to) && related_to
  str << "\ndescription: |\n#{indent(description)}\n"
end