Class: Chiridion::Engine::DocumentModel::FileDoc

Inherits:
Data
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#line_countObject (readonly)

Returns the value of attribute line_count

Returns:

  • (Object)

    the current value of line_count



233
234
235
# File 'lib/chiridion/engine/document_model.rb', line 233

def line_count
  @line_count
end

#namespacesObject (readonly)

Returns the value of attribute namespaces

Returns:

  • (Object)

    the current value of namespaces



233
234
235
# File 'lib/chiridion/engine/document_model.rb', line 233

def namespaces
  @namespaces
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



233
234
235
# File 'lib/chiridion/engine/document_model.rb', line 233

def path
  @path
end

#type_aliasesObject (readonly)

Returns the value of attribute type_aliases

Returns:

  • (Object)

    the current value of type_aliases



233
234
235
# File 'lib/chiridion/engine/document_model.rb', line 233

def type_aliases
  @type_aliases
end

Instance Method Details

#classesObject



281
# File 'lib/chiridion/engine/document_model.rb', line 281

def classes = namespaces.select { |n| n.type == :class }

#dirnameObject

Directory portion (e.g., “lib/archema”)



243
# File 'lib/chiridion/engine/document_model.rb', line 243

def dirname = File.dirname(path)

#filenameObject

Short filename for display (e.g., “attributes.rb”)



240
# File 'lib/chiridion/engine/document_model.rb', line 240

def filename = File.basename(path)

#modulesObject



282
# File 'lib/chiridion/engine/document_model.rb', line 282

def modules = namespaces.select { |n| n.type == :module }

#primary_namespaceObject

Main namespace - the one that best represents this file’s purpose.

Selection order:

  1. Namespace whose name matches filename (query.rb -> Query)

  2. Module (often the container for nested classes)

  3. Shortest path (top-level namespace)

  4. 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