Class: Glossarist::Validation::Rules::ConceptContext
- Inherits:
-
Object
- Object
- Glossarist::Validation::Rules::ConceptContext
- Defined in:
- lib/glossarist/validation/rules/concept_context.rb
Overview
Shared context for concept-scoped validation rules.
Provides lazy-memoized access to extracted references so that multiple rules examining the same concept share one extraction pass (DRY, single source of truth). Rules ask the context for references rather than instantiating their own ReferenceExtractor.
In V3, n-ary relations (PartitiveHyperedge, GenericHyperedge) are
per-file (see Glossarist::V3::RelationLoader). Each concept's
relations are looked up via the relations lookup passed here.
Pass an explicit relations: list when constructing the context
— the loader does not run on demand so the validator behaviour
is fully deterministic given the load.
Instance Attribute Summary collapse
-
#collection_context ⇒ Object
readonly
Returns the value of attribute collection_context.
-
#concept ⇒ Object
readonly
Returns the value of attribute concept.
-
#concept_resolver ⇒ Object
readonly
Returns the value of attribute concept_resolver.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
- #asset_index ⇒ Object
-
#asset_references ⇒ Object
All asset references (NonVerbRep, GraphicalSymbol) extracted from the concept's model attributes.
- #bibliography_index ⇒ Object
- #concept_id ⇒ Object
- #concept_ids ⇒ Object
- #declared_languages ⇒ Object
- #gcr? ⇒ Boolean
-
#initialize(concept, file_name:, collection_context:, relations: [], concept_resolver: nil) ⇒ ConceptContext
constructor
concept_resolveris an optional callable that takes a ConceptRef and returns the resolved ManagedConcept (or nil). - #metadata ⇒ Object
-
#references ⇒ Object
All references extracted from the concept's text fields (definitions, notes, examples) via {...} mentions, <
>, and image::...[] references.
Constructor Details
#initialize(concept, file_name:, collection_context:, relations: [], concept_resolver: nil) ⇒ ConceptContext
concept_resolver is an optional callable that takes a
ConceptRef and returns the resolved ManagedConcept (or nil).
Rules that need cross-concept lookups (e.g.,
ExternalConceptRule's dangling-external detection) use this.
When nil, those rules no-op.
28 29 30 31 32 33 34 35 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 28 def initialize(concept, file_name:, collection_context:, relations: [], concept_resolver: nil) @concept = concept @file_name = file_name @collection_context = collection_context @relations = Array(relations) @concept_resolver = concept_resolver end |
Instance Attribute Details
#collection_context ⇒ Object (readonly)
Returns the value of attribute collection_context.
20 21 22 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 20 def collection_context @collection_context end |
#concept ⇒ Object (readonly)
Returns the value of attribute concept.
20 21 22 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 20 def concept @concept end |
#concept_resolver ⇒ Object (readonly)
Returns the value of attribute concept_resolver.
20 21 22 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 20 def concept_resolver @concept_resolver end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
20 21 22 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 20 def file_name @file_name end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
20 21 22 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 20 def relations @relations end |
Instance Method Details
#asset_index ⇒ Object
63 64 65 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 63 def asset_index @collection_context.asset_index end |
#asset_references ⇒ Object
All asset references (NonVerbRep, GraphicalSymbol) extracted from the concept's model attributes. Memoized — extracted once per concept, shared across all rules.
54 55 56 57 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 54 def asset_references @asset_references ||= ReferenceExtractor.new .extract_asset_refs_from_concept(@concept) end |
#bibliography_index ⇒ Object
59 60 61 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 59 def bibliography_index @collection_context.bibliography_index end |
#concept_id ⇒ Object
37 38 39 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 37 def concept_id @concept.data&.id&.to_s end |
#concept_ids ⇒ Object
67 68 69 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 67 def concept_ids @collection_context.concept_ids end |
#declared_languages ⇒ Object
71 72 73 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 71 def declared_languages @collection_context.declared_languages end |
#gcr? ⇒ Boolean
79 80 81 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 79 def gcr? @collection_context.gcr? end |
#metadata ⇒ Object
75 76 77 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 75 def @collection_context. end |
#references ⇒ Object
All references extracted from the concept's text fields
(definitions, notes, examples) via {...} mentions, <
46 47 48 49 |
# File 'lib/glossarist/validation/rules/concept_context.rb', line 46 def references @references ||= ReferenceExtractor.new .extract_from_managed_concept(@concept) end |