Class: Ace::Docs::Organisms::DocumentRegistry
- Inherits:
-
Object
- Object
- Ace::Docs::Organisms::DocumentRegistry
- Defined in:
- lib/ace/docs/organisms/document_registry.rb
Overview
Discovers and indexes all managed documents in the project
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
Instance Method Summary collapse
-
#all ⇒ Object
Find all managed documents.
-
#by_freshness(status) ⇒ Object
Find documents by freshness status.
-
#by_type(doc_type) ⇒ Object
Find documents by type.
-
#document_types ⇒ Object
Get document types configuration.
-
#find_by_path(path) ⇒ Object
Find document by path.
-
#global_rules ⇒ Object
Get global validation rules.
-
#grouped_by_directory ⇒ Object
Group documents by directory.
-
#grouped_by_type ⇒ Object
Group documents by type.
-
#initialize(project_root: nil, config: nil, scope_globs: nil) ⇒ DocumentRegistry
constructor
Initialize the document registry.
-
#needing_update ⇒ Object
Find documents needing update.
-
#refresh ⇒ Object
Refresh the registry by rediscovering documents.
-
#stats ⇒ Object
Get statistics about the registry.
Constructor Details
#initialize(project_root: nil, config: nil, scope_globs: nil) ⇒ DocumentRegistry
Initialize the document registry
18 19 20 21 22 23 24 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 18 def initialize(project_root: nil, config: nil, scope_globs: nil) @project_root = project_root || determine_project_root @config = config || Ace::Docs.config @scope_globs = Array(scope_globs).compact @documents = [] discover_documents end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 13 def config @config end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
13 14 15 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 13 def documents @documents end |
Instance Method Details
#all ⇒ Object
Find all managed documents
33 34 35 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 33 def all @documents.dup end |
#by_freshness(status) ⇒ Object
Find documents by freshness status
48 49 50 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 48 def by_freshness(status) @documents.select { |doc| doc.freshness_status == status } end |
#by_type(doc_type) ⇒ Object
Find documents by type
38 39 40 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 38 def by_type(doc_type) @documents.select { |doc| doc.doc_type == doc_type } end |
#document_types ⇒ Object
Get document types configuration
61 62 63 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 61 def document_types @config["document_types"] || {} end |
#find_by_path(path) ⇒ Object
Find document by path
53 54 55 56 57 58 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 53 def find_by_path(path) return nil unless File.exist?(path) real_path = File.realpath(path) @documents.find { |doc| File.exist?(doc.path) && File.realpath(doc.path) == real_path } end |
#global_rules ⇒ Object
Get global validation rules
66 67 68 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 66 def global_rules @config["global_rules"] || {} end |
#grouped_by_directory ⇒ Object
Group documents by directory
76 77 78 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 76 def grouped_by_directory @documents.group_by { |doc| File.dirname(doc.path) } end |
#grouped_by_type ⇒ Object
Group documents by type
71 72 73 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 71 def grouped_by_type @documents.group_by(&:doc_type) end |
#needing_update ⇒ Object
Find documents needing update
43 44 45 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 43 def needing_update @documents.select(&:needs_update?) end |
#refresh ⇒ Object
Refresh the registry by rediscovering documents
27 28 29 30 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 27 def refresh @documents = [] discover_documents end |
#stats ⇒ Object
Get statistics about the registry
81 82 83 84 85 86 87 88 89 |
# File 'lib/ace/docs/organisms/document_registry.rb', line 81 def stats { total: @documents.size, by_type: @documents.group_by(&:doc_type).transform_values(&:size), by_freshness: @documents.group_by(&:freshness_status).transform_values(&:size), needing_update: needing_update.size, managed: @documents.count(&:managed?) } end |