Class: Chiridion::Engine::DocumentModel::FileDoc
- Inherits:
-
Data
- Object
- Data
- Chiridion::Engine::DocumentModel::FileDoc
- Defined in:
- lib/chiridion/engine/document_model.rb
Overview
Documentation for a single source file.
Groups all namespaces (classes/modules) defined in one Ruby file. This is the primary unit for per-file documentation output.
Instance Attribute Summary collapse
-
#line_count ⇒ Object
readonly
Returns the value of attribute line_count.
-
#namespaces ⇒ Object
readonly
Returns the value of attribute namespaces.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#type_aliases ⇒ Object
readonly
Returns the value of attribute type_aliases.
Instance Method Summary collapse
- #classes ⇒ Object
-
#dirname ⇒ Object
Directory portion (e.g., “lib/archema”).
-
#filename ⇒ Object
Short filename for display (e.g., “attributes.rb”).
- #modules ⇒ Object
-
#primary_namespace ⇒ Object
Main namespace - the one that best represents this file’s purpose.
Instance Attribute Details
#line_count ⇒ Object (readonly)
Returns the value of attribute line_count
233 234 235 |
# File 'lib/chiridion/engine/document_model.rb', line 233 def line_count @line_count end |
#namespaces ⇒ Object (readonly)
Returns the value of attribute namespaces
233 234 235 |
# File 'lib/chiridion/engine/document_model.rb', line 233 def namespaces @namespaces end |
#path ⇒ Object (readonly)
Returns the value of attribute path
233 234 235 |
# File 'lib/chiridion/engine/document_model.rb', line 233 def path @path end |
#type_aliases ⇒ Object (readonly)
Returns the value of attribute type_aliases
233 234 235 |
# File 'lib/chiridion/engine/document_model.rb', line 233 def type_aliases @type_aliases end |
Instance Method Details
#classes ⇒ Object
281 |
# File 'lib/chiridion/engine/document_model.rb', line 281 def classes = namespaces.select { |n| n.type == :class } |
#dirname ⇒ Object
Directory portion (e.g., “lib/archema”)
243 |
# File 'lib/chiridion/engine/document_model.rb', line 243 def dirname = File.dirname(path) |
#filename ⇒ Object
Short filename for display (e.g., “attributes.rb”)
240 |
# File 'lib/chiridion/engine/document_model.rb', line 240 def filename = File.basename(path) |
#modules ⇒ Object
282 |
# File 'lib/chiridion/engine/document_model.rb', line 282 def modules = namespaces.select { |n| n.type == :module } |
#primary_namespace ⇒ Object
Main namespace - the one that best represents this file’s purpose.
Selection order:
-
Namespace whose name matches filename (query.rb -> Query)
-
Module (often the container for nested classes)
-
Shortest path (top-level namespace)
-
Most content as tiebreaker
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/chiridion/engine/document_model.rb', line 252 def primary_namespace return namespaces.first if namespaces.size == 1 return nil if namespaces.empty? basename = File.basename(path, ".rb") # Convert snake_case to variations for matching name_variants = [ basename, # document_model basename.gsub("_", ""), # documentmodel basename.split("_").map(&:capitalize).join # DocumentModel ] # Try to find namespace whose name matches filename name_match = namespaces.find do |n| name_variants.any? { |v| n.name.downcase == v.downcase } end return name_match if name_match # Prefer modules (they're usually the container) modules_list = namespaces.select { |n| n.type == :module } if modules_list.any? # Among modules, prefer shortest path (top-level) return modules_list.min_by { |n| n.path.count("::") } end # Among classes, prefer shortest path namespaces.min_by { |n| n.path.count("::") } end |