coridoc 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/Rakefile +8 -0
  4. data/exe/coridoc +24 -0
  5. data/lib/coridoc/binding_inflater.rb +118 -0
  6. data/lib/coridoc/cli.rb +311 -0
  7. data/lib/coridoc/configurable.rb +530 -0
  8. data/lib/coridoc/core_model/abstract_block.rb +11 -0
  9. data/lib/coridoc/core_model/annotation_block.rb +57 -0
  10. data/lib/coridoc/core_model/attribute_reference_resolver.rb +155 -0
  11. data/lib/coridoc/core_model/base.rb +281 -0
  12. data/lib/coridoc/core_model/bibliography.rb +41 -0
  13. data/lib/coridoc/core_model/bibliography_entry.rb +48 -0
  14. data/lib/coridoc/core_model/block.rb +69 -0
  15. data/lib/coridoc/core_model/callout.rb +32 -0
  16. data/lib/coridoc/core_model/callout_text.rb +35 -0
  17. data/lib/coridoc/core_model/children_content.rb +72 -0
  18. data/lib/coridoc/core_model/comment_block.rb +16 -0
  19. data/lib/coridoc/core_model/comment_line.rb +23 -0
  20. data/lib/coridoc/core_model/definition_item.rb +68 -0
  21. data/lib/coridoc/core_model/definition_list.rb +28 -0
  22. data/lib/coridoc/core_model/element_attribute.rb +14 -0
  23. data/lib/coridoc/core_model/example_block.rb +12 -0
  24. data/lib/coridoc/core_model/footnote.rb +92 -0
  25. data/lib/coridoc/core_model/frontmatter/codec.rb +151 -0
  26. data/lib/coridoc/core_model/frontmatter/field_transform.rb +75 -0
  27. data/lib/coridoc/core_model/frontmatter/frontmatter_entry.rb +22 -0
  28. data/lib/coridoc/core_model/frontmatter/frontmatter_value.rb +78 -0
  29. data/lib/coridoc/core_model/frontmatter/schema_resolver.rb +57 -0
  30. data/lib/coridoc/core_model/frontmatter/text_splitter.rb +75 -0
  31. data/lib/coridoc/core_model/frontmatter.rb +72 -0
  32. data/lib/coridoc/core_model/has_children.rb +23 -0
  33. data/lib/coridoc/core_model/horizontal_rule_block.rb +16 -0
  34. data/lib/coridoc/core_model/id_generator.rb +23 -0
  35. data/lib/coridoc/core_model/image.rb +69 -0
  36. data/lib/coridoc/core_model/include.rb +43 -0
  37. data/lib/coridoc/core_model/include_level_offset.rb +71 -0
  38. data/lib/coridoc/core_model/include_options.rb +101 -0
  39. data/lib/coridoc/core_model/inline_content.rb +78 -0
  40. data/lib/coridoc/core_model/inline_element.rb +198 -0
  41. data/lib/coridoc/core_model/list_block.rb +137 -0
  42. data/lib/coridoc/core_model/list_item.rb +129 -0
  43. data/lib/coridoc/core_model/listing_block.rb +19 -0
  44. data/lib/coridoc/core_model/literal_block.rb +16 -0
  45. data/lib/coridoc/core_model/metadata.rb +71 -0
  46. data/lib/coridoc/core_model/open_block.rb +12 -0
  47. data/lib/coridoc/core_model/output_artifact.rb +48 -0
  48. data/lib/coridoc/core_model/paragraph_block.rb +16 -0
  49. data/lib/coridoc/core_model/partintro_block.rb +11 -0
  50. data/lib/coridoc/core_model/pass_block.rb +16 -0
  51. data/lib/coridoc/core_model/quote_block.rb +14 -0
  52. data/lib/coridoc/core_model/raw_inline_element.rb +16 -0
  53. data/lib/coridoc/core_model/reviewer_block.rb +12 -0
  54. data/lib/coridoc/core_model/sidebar_block.rb +12 -0
  55. data/lib/coridoc/core_model/source_block.rb +16 -0
  56. data/lib/coridoc/core_model/stem_block.rb +25 -0
  57. data/lib/coridoc/core_model/structural_element.rb +157 -0
  58. data/lib/coridoc/core_model/table.rb +148 -0
  59. data/lib/coridoc/core_model/term.rb +53 -0
  60. data/lib/coridoc/core_model/text_content.rb +26 -0
  61. data/lib/coridoc/core_model/toc.rb +99 -0
  62. data/lib/coridoc/core_model/toc_generator.rb +151 -0
  63. data/lib/coridoc/core_model/verse_block.rb +14 -0
  64. data/lib/coridoc/core_model.rb +92 -0
  65. data/lib/coridoc/coridoc.rb +164 -0
  66. data/lib/coridoc/dispatch.rb +96 -0
  67. data/lib/coridoc/errors.rb +387 -0
  68. data/lib/coridoc/format_catalog.rb +102 -0
  69. data/lib/coridoc/format_module.rb +78 -0
  70. data/lib/coridoc/hooks.rb +176 -0
  71. data/lib/coridoc/include_resolver/filesystem.rb +84 -0
  72. data/lib/coridoc/include_resolver.rb +67 -0
  73. data/lib/coridoc/include_selectors/indent.rb +54 -0
  74. data/lib/coridoc/include_selectors/level_offset.rb +84 -0
  75. data/lib/coridoc/include_selectors/lines.rb +60 -0
  76. data/lib/coridoc/include_selectors/tags.rb +136 -0
  77. data/lib/coridoc/include_selectors.rb +26 -0
  78. data/lib/coridoc/introspection/element_counter.rb +48 -0
  79. data/lib/coridoc/introspection.rb +72 -0
  80. data/lib/coridoc/link_rewriter/identity.rb +13 -0
  81. data/lib/coridoc/link_rewriter/visitor.rb +148 -0
  82. data/lib/coridoc/link_rewriter.rb +37 -0
  83. data/lib/coridoc/lint/registry.rb +33 -0
  84. data/lib/coridoc/lint/rule.rb +41 -0
  85. data/lib/coridoc/lint/runner.rb +67 -0
  86. data/lib/coridoc/lint/template.rb +190 -0
  87. data/lib/coridoc/lint/violation.rb +16 -0
  88. data/lib/coridoc/lint.rb +44 -0
  89. data/lib/coridoc/logger.rb +54 -0
  90. data/lib/coridoc/performance_regression.rb +121 -0
  91. data/lib/coridoc/pipeline.rb +169 -0
  92. data/lib/coridoc/query.rb +486 -0
  93. data/lib/coridoc/reference/address/anchor.rb +48 -0
  94. data/lib/coridoc/reference/address/doi.rb +40 -0
  95. data/lib/coridoc/reference/address/isbn.rb +39 -0
  96. data/lib/coridoc/reference/address/path.rb +66 -0
  97. data/lib/coridoc/reference/address/scoped_path.rb +47 -0
  98. data/lib/coridoc/reference/address/url.rb +41 -0
  99. data/lib/coridoc/reference/address.rb +153 -0
  100. data/lib/coridoc/reference/catalog/composite.rb +59 -0
  101. data/lib/coridoc/reference/catalog/local.rb +97 -0
  102. data/lib/coridoc/reference/catalog/memory_index.rb +59 -0
  103. data/lib/coridoc/reference/catalog.rb +33 -0
  104. data/lib/coridoc/reference/edge/citation_options.rb +16 -0
  105. data/lib/coridoc/reference/edge/footnote_ref_options.rb +13 -0
  106. data/lib/coridoc/reference/edge/image_ref_options.rb +15 -0
  107. data/lib/coridoc/reference/edge/include_options.rb +15 -0
  108. data/lib/coridoc/reference/edge/kind.rb +72 -0
  109. data/lib/coridoc/reference/edge/link_options.rb +12 -0
  110. data/lib/coridoc/reference/edge/navigation_options.rb +12 -0
  111. data/lib/coridoc/reference/edge/options.rb +13 -0
  112. data/lib/coridoc/reference/edge.rb +80 -0
  113. data/lib/coridoc/reference/edge_search.rb +128 -0
  114. data/lib/coridoc/reference/materializer/base.rb +44 -0
  115. data/lib/coridoc/reference/materializer/passthrough.rb +31 -0
  116. data/lib/coridoc/reference/materializer/registry.rb +116 -0
  117. data/lib/coridoc/reference/materializer.rb +14 -0
  118. data/lib/coridoc/reference/presentation/base.rb +47 -0
  119. data/lib/coridoc/reference/presentation/custom_hierarchy.rb +104 -0
  120. data/lib/coridoc/reference/presentation/page.rb +20 -0
  121. data/lib/coridoc/reference/presentation/single_document.rb +35 -0
  122. data/lib/coridoc/reference/presentation/split_pages.rb +118 -0
  123. data/lib/coridoc/reference/presentation.rb +16 -0
  124. data/lib/coridoc/reference/resolution.rb +184 -0
  125. data/lib/coridoc/reference/resolver/base.rb +15 -0
  126. data/lib/coridoc/reference/resolver/caching.rb +37 -0
  127. data/lib/coridoc/reference/resolver/catalog.rb +69 -0
  128. data/lib/coridoc/reference/resolver/chain.rb +33 -0
  129. data/lib/coridoc/reference/resolver.rb +20 -0
  130. data/lib/coridoc/reference/result/ambiguous.rb +23 -0
  131. data/lib/coridoc/reference/result/base.rb +46 -0
  132. data/lib/coridoc/reference/result/missing.rb +14 -0
  133. data/lib/coridoc/reference/result/resolved.rb +22 -0
  134. data/lib/coridoc/reference/result.rb +20 -0
  135. data/lib/coridoc/reference.rb +65 -0
  136. data/lib/coridoc/registry.rb +156 -0
  137. data/lib/coridoc/relative_path.rb +32 -0
  138. data/lib/coridoc/resolve_includes.rb +202 -0
  139. data/lib/coridoc/source_graph/file_node.rb +147 -0
  140. data/lib/coridoc/source_graph/graph.rb +165 -0
  141. data/lib/coridoc/source_graph/include_edges.rb +33 -0
  142. data/lib/coridoc/source_graph/sidecar.rb +97 -0
  143. data/lib/coridoc/source_graph.rb +36 -0
  144. data/lib/coridoc/validation.rb +686 -0
  145. data/lib/coridoc/version.rb +5 -0
  146. data/lib/coridoc/visitor.rb +283 -0
  147. data/lib/coridoc.rb +41 -0
  148. metadata +221 -0
@@ -0,0 +1,530 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ # Global configuration system for Coridoc.
5
+ #
6
+ # Provides centralized configuration management with support for:
7
+ # - Configuration files (.coridoc.yml)
8
+ # - Environment-specific settings
9
+ # - Per-module configuration merging
10
+ # - Validation of configuration values
11
+ #
12
+ # @example Basic configuration
13
+ # Coridoc.configure do |config|
14
+ # config.default_format = :asciidoc
15
+ # config.cache.enabled = true
16
+ # config.cache.max_size = 1000
17
+ # end
18
+ #
19
+ # @example Environment-specific configuration
20
+ # Coridoc.configure do |config|
21
+ # config.environment = ENV.fetch("RACK_ENV", "development")
22
+ # config.cache.enabled = config.production?
23
+ # end
24
+ #
25
+ # @example Loading from file
26
+ # Coridoc::Configuration.load_file(".coridoc.yml")
27
+ #
28
+ module Configurable
29
+ # Configuration error
30
+ class ConfigurationError < Coridoc::Error; end
31
+
32
+ # Base class for configuration sections
33
+ class ConfigSection
34
+ # @return [Hash] Raw configuration values
35
+ attr_reader :options
36
+
37
+ def self.symbolize_keys(hash)
38
+ return {} unless hash.is_a?(Hash)
39
+
40
+ hash.transform_keys(&:to_sym)
41
+ end
42
+
43
+ # Create a configuration section
44
+ #
45
+ # @param options [Hash] Configuration options
46
+ def initialize(options = {})
47
+ @options = symbolize_keys(options)
48
+ after_initialize
49
+ end
50
+
51
+ # Hook for subclass initialization
52
+ def after_initialize; end
53
+
54
+ # Get a configuration value
55
+ #
56
+ # @param key [Symbol] Configuration key
57
+ # @return [Object] Configuration value
58
+ def [](key)
59
+ @options[key]
60
+ end
61
+
62
+ # Set a configuration value
63
+ #
64
+ # @param key [Symbol] Configuration key
65
+ # @param value [Object] Configuration value
66
+ def []=(key, value)
67
+ @options[key] = value
68
+ end
69
+
70
+ # Merge options into this section
71
+ #
72
+ # @param other [Hash, ConfigSection] Options to merge
73
+ # @return [void]
74
+ def merge!(other)
75
+ other_options = other.is_a?(ConfigSection) ? other.options : other
76
+ other_options = symbolize_keys(other_options)
77
+ @options.merge!(other_options)
78
+ # Apply merged options to accessors
79
+ apply_options(other_options)
80
+ end
81
+
82
+ # Convert to hash
83
+ #
84
+ # @return [Hash]
85
+ def to_h
86
+ @options.transform_values do |v|
87
+ v.is_a?(ConfigSection) ? v.to_h : v
88
+ end
89
+ end
90
+
91
+ private
92
+
93
+ def symbolize_keys(hash)
94
+ self.class.symbolize_keys(hash)
95
+ end
96
+
97
+ # Apply options to instance variables
98
+ # Override in subclasses for custom handling
99
+ def apply_options(options)
100
+ options.each do |key, value|
101
+ setter = "#{key}="
102
+ # Use public_send (not instance_variable_set) so we route
103
+ # through the public setter method — encapsulation is
104
+ # preserved and any setter-side validation runs.
105
+ public_send(setter, value) if public_methods.include?(setter.to_sym)
106
+ end
107
+ end
108
+ end
109
+
110
+ # Cache configuration section
111
+ class CacheConfig < ConfigSection
112
+ # @return [Boolean] Whether caching is enabled
113
+ attr_accessor :enabled
114
+
115
+ # @return [Integer] Maximum cache size (number of entries)
116
+ attr_accessor :max_size
117
+
118
+ # @return [Integer] Cache TTL in seconds (0 = no expiry)
119
+ attr_accessor :ttl
120
+
121
+ # @return [Symbol] Cache storage backend (:memory, :file, :redis)
122
+ attr_accessor :backend
123
+
124
+ # @return [String, nil] Cache directory for file backend
125
+ attr_accessor :cache_dir
126
+
127
+ def initialize(options = {})
128
+ super
129
+ @enabled = @options.fetch(:enabled, true)
130
+ @max_size = @options.fetch(:max_size, 1000)
131
+ @ttl = @options.fetch(:ttl, 0)
132
+ @backend = @options.fetch(:backend, :memory)
133
+ @cache_dir = @options.fetch(:cache_dir, nil)
134
+ end
135
+ end
136
+
137
+ # Parser configuration section
138
+ class ParserConfig < ConfigSection
139
+ # @return [Boolean] Enable parser caching
140
+ attr_accessor :cache_enabled
141
+
142
+ # @return [Boolean] Strict parsing mode
143
+ attr_accessor :strict_mode
144
+
145
+ # @return [Boolean] Include source location in AST
146
+ attr_accessor :include_source_loc
147
+
148
+ # @return [Integer] Maximum nesting depth
149
+ attr_accessor :max_nesting_depth
150
+
151
+ def initialize(options = {})
152
+ super
153
+ @cache_enabled = @options.fetch(:cache_enabled, true)
154
+ @strict_mode = @options.fetch(:strict_mode, false)
155
+ @include_source_loc = @options.fetch(:include_source_loc, true)
156
+ @max_nesting_depth = @options.fetch(:max_nesting_depth, 100)
157
+ end
158
+ end
159
+
160
+ # Transformer configuration section
161
+ class TransformerConfig < ConfigSection
162
+ # @return [Boolean] Enable transformation caching
163
+ attr_accessor :cache_enabled
164
+
165
+ # @return [Boolean] Preserve unknown elements
166
+ attr_accessor :preserve_unknown
167
+
168
+ # @return [Boolean] Validate after transformation
169
+ attr_accessor :validate_output
170
+
171
+ # @return [Array<Symbol>] Enabled transformers
172
+ attr_accessor :enabled_transformers
173
+
174
+ def initialize(options = {})
175
+ super
176
+ @cache_enabled = @options.fetch(:cache_enabled, true)
177
+ @preserve_unknown = @options.fetch(:preserve_unknown, true)
178
+ @validate_output = @options.fetch(:validate_output, false)
179
+ @enabled_transformers = @options.fetch(:enabled_transformers, [])
180
+ end
181
+ end
182
+
183
+ # Output configuration section
184
+ class OutputConfig < ConfigSection
185
+ # @return [Symbol] Default output format
186
+ attr_accessor :default_format
187
+
188
+ # @return [Boolean] Pretty print output
189
+ attr_accessor :pretty_print
190
+
191
+ # @return [Integer] Line width for text output
192
+ attr_accessor :line_width
193
+
194
+ # @return [String] Indentation string
195
+ attr_accessor :indent
196
+
197
+ # @return [Boolean] Include metadata in output
198
+ attr_accessor :include_metadata
199
+
200
+ def initialize(options = {})
201
+ super
202
+ @default_format = @options.fetch(:default_format, :html)
203
+ @pretty_print = @options.fetch(:pretty_print, true)
204
+ @line_width = @options.fetch(:line_width, 80)
205
+ @indent = @options.fetch(:indent, ' ')
206
+ @include_metadata = @options.fetch(:include_metadata, false)
207
+ end
208
+ end
209
+
210
+ # Logging configuration section
211
+ class LoggingConfig < ConfigSection
212
+ # @return [Symbol] Log level (:debug, :info, :warn, :error)
213
+ attr_accessor :level
214
+
215
+ # @return [Boolean] Include timestamps
216
+ attr_accessor :timestamps
217
+
218
+ # @return [IO, nil] Log output destination
219
+ attr_accessor :output
220
+
221
+ # @return [Boolean] Colorize output
222
+ attr_accessor :colorize
223
+
224
+ def initialize(options = {})
225
+ super
226
+ @level = @options.fetch(:level, :info)
227
+ @timestamps = @options.fetch(:timestamps, true)
228
+ @output = @options.fetch(:output, $stderr)
229
+ @colorize = @options.fetch(:colorize, true)
230
+ end
231
+ end
232
+
233
+ # Main configuration class
234
+ class Configuration
235
+ # @return [String] Current environment
236
+ attr_accessor :environment
237
+
238
+ # @return [CacheConfig] Cache configuration
239
+ attr_reader :cache
240
+
241
+ # @return [ParserConfig] Parser configuration
242
+ attr_reader :parser
243
+
244
+ # @return [TransformerConfig] Transformer configuration
245
+ attr_reader :transformer
246
+
247
+ # @return [OutputConfig] Output configuration
248
+ attr_reader :output
249
+
250
+ # @return [LoggingConfig] Logging configuration
251
+ attr_reader :logging
252
+
253
+ # @return [Hash] Custom configuration values
254
+ attr_reader :custom
255
+
256
+ # Create a new configuration
257
+ #
258
+ # @param options [Hash] Configuration options
259
+ def initialize(options = {})
260
+ options = symbolize_keys(options)
261
+ @environment = options.fetch(:environment, detect_environment)
262
+ @cache = CacheConfig.new(options[:cache] || {})
263
+ @parser = ParserConfig.new(options[:parser] || {})
264
+ @transformer = TransformerConfig.new(options[:transformer] || {})
265
+ @output = OutputConfig.new(options[:output] || {})
266
+ @logging = LoggingConfig.new(options[:logging] || {})
267
+ @custom = options.fetch(:custom, {})
268
+ end
269
+
270
+ # Check if running in development environment
271
+ #
272
+ # @return [Boolean]
273
+ def development?
274
+ @environment == 'development'
275
+ end
276
+
277
+ # Check if running in production environment
278
+ #
279
+ # @return [Boolean]
280
+ def production?
281
+ @environment == 'production'
282
+ end
283
+
284
+ # Check if running in test environment
285
+ #
286
+ # @return [Boolean]
287
+ def test?
288
+ @environment == 'test'
289
+ end
290
+
291
+ # Get a custom configuration value
292
+ #
293
+ # @param key [Symbol] Configuration key
294
+ # @return [Object] Configuration value
295
+ def [](key)
296
+ @custom[key.to_sym]
297
+ end
298
+
299
+ # Set a custom configuration value
300
+ #
301
+ # @param key [Symbol] Configuration key
302
+ # @param value [Object] Configuration value
303
+ def []=(key, value)
304
+ @custom[key.to_sym] = value
305
+ end
306
+
307
+ # Merge another configuration into this one
308
+ #
309
+ # @param other [Configuration, Hash] Configuration to merge
310
+ # @return [void]
311
+ def merge!(other)
312
+ case other
313
+ when Configuration
314
+ @environment = other.environment if other.environment != detect_environment
315
+ @cache.merge!(other.cache)
316
+ @parser.merge!(other.parser)
317
+ @transformer.merge!(other.transformer)
318
+ @output.merge!(other.output)
319
+ @logging.merge!(other.logging)
320
+ @custom.merge!(other.custom)
321
+ when Hash
322
+ merge_hash(other)
323
+ end
324
+ end
325
+
326
+ # Create a copy of this configuration
327
+ #
328
+ # @return [Configuration]
329
+ def dup
330
+ self.class.new(to_h)
331
+ end
332
+
333
+ # Convert configuration to hash
334
+ #
335
+ # @return [Hash]
336
+ def to_h
337
+ {
338
+ environment: @environment,
339
+ cache: @cache.to_h,
340
+ parser: @parser.to_h,
341
+ transformer: @transformer.to_h,
342
+ output: @output.to_h,
343
+ logging: @logging.to_h,
344
+ custom: @custom.dup
345
+ }
346
+ end
347
+
348
+ # Load configuration from a YAML file
349
+ #
350
+ # @param path [String] Path to configuration file
351
+ # @return [Configuration] Loaded configuration
352
+ # @raise [ConfigurationError] If file cannot be loaded
353
+ def self.load_file(path)
354
+ require 'yaml'
355
+
356
+ raise ConfigurationError, "Configuration file not found: #{path}" unless File.exist?(path)
357
+
358
+ begin
359
+ yaml_content = YAML.load_file(path)
360
+ new(yaml_content || {})
361
+ rescue Psych::SyntaxError => e
362
+ raise ConfigurationError, "Invalid YAML in #{path}: #{e.message}"
363
+ end
364
+ end
365
+
366
+ # Load configuration from environment variables
367
+ #
368
+ # @param prefix [String] Environment variable prefix
369
+ # @return [Configuration] Configuration from environment
370
+ def self.load_environment(prefix = 'CORIDOC')
371
+ options = {}
372
+
373
+ # Parse CORIDOC_CACHE_ENABLED=true style variables
374
+ ENV.each do |key, value|
375
+ next unless key.start_with?("#{prefix}_")
376
+
377
+ # Convert CORIDOC_CACHE_ENABLED to [:cache, :enabled]
378
+ parts = key.sub("#{prefix}_", '').downcase.split('_')
379
+ next if parts.length < 2
380
+
381
+ section = parts.first.to_sym
382
+ setting = parts[1..].join('_').to_sym
383
+
384
+ options[section] ||= {}
385
+ options[section][setting] = parse_env_value(value)
386
+ end
387
+
388
+ # Special handling for CORIDOC_ENV
389
+ options[:environment] = ENV["#{prefix}_ENV"] if ENV["#{prefix}_ENV"]
390
+
391
+ new(options)
392
+ end
393
+
394
+ # Reset configuration to defaults
395
+ #
396
+ # @return [void]
397
+ def reset!
398
+ @environment = detect_environment
399
+ @cache = CacheConfig.new
400
+ @parser = ParserConfig.new
401
+ @transformer = TransformerConfig.new
402
+ @output = OutputConfig.new
403
+ @logging = LoggingConfig.new
404
+ @custom = {}
405
+ end
406
+
407
+ # Validate configuration
408
+ #
409
+ # @return [Array<String>] List of validation errors
410
+ def validate
411
+ errors = []
412
+
413
+ errors << 'cache.max_size must be positive' if @cache.max_size <= 0
414
+ errors << 'cache.ttl must be non-negative' if @cache.ttl.negative?
415
+ errors << 'parser.max_nesting_depth must be positive' if @parser.max_nesting_depth <= 0
416
+ errors << 'output.line_width must be positive' if @output.line_width <= 0
417
+
418
+ errors << 'cache.backend must be :memory, :file, or :redis' unless %i[memory file
419
+ redis].include?(@cache.backend)
420
+
421
+ errors << 'logging.level must be :debug, :info, :warn, or :error' unless %i[debug info warn
422
+ error].include?(@logging.level)
423
+
424
+ errors
425
+ end
426
+
427
+ # Check if configuration is valid
428
+ #
429
+ # @return [Boolean]
430
+ def valid?
431
+ validate.empty?
432
+ end
433
+
434
+ private
435
+
436
+ def detect_environment
437
+ ENV.fetch('RACK_ENV', ENV.fetch('RAILS_ENV', 'development'))
438
+ end
439
+
440
+ def symbolize_keys(hash)
441
+ ConfigSection.symbolize_keys(hash)
442
+ end
443
+
444
+ def merge_hash(hash)
445
+ hash = symbolize_keys(hash)
446
+
447
+ @environment = hash[:environment] if hash.key?(:environment)
448
+ @cache.merge!(hash[:cache]) if hash.key?(:cache)
449
+ @parser.merge!(hash[:parser]) if hash.key?(:parser)
450
+ @transformer.merge!(hash[:transformer]) if hash.key?(:transformer)
451
+ @output.merge!(hash[:output]) if hash.key?(:output)
452
+ @logging.merge!(hash[:logging]) if hash.key?(:logging)
453
+ @custom.merge!(symbolize_keys(hash[:custom] || {}))
454
+ end
455
+
456
+ def self.parse_env_value(value)
457
+ case value.downcase
458
+ when 'true', 'yes', '1'
459
+ true
460
+ when 'false', 'no', '0'
461
+ false
462
+ when /^\d+$/
463
+ value.to_i
464
+ when /^\d+\.\d+$/
465
+ value.to_f
466
+ else
467
+ value
468
+ end
469
+ end
470
+ private_class_method :parse_env_value
471
+ end
472
+
473
+ class << self
474
+ # Get current global configuration
475
+ #
476
+ # @return [Configuration]
477
+ def configuration
478
+ @configuration ||= Configuration.new
479
+ end
480
+
481
+ # Set global configuration
482
+ #
483
+ # @param config [Configuration] Configuration to set
484
+ # @return [void]
485
+ attr_writer :configuration
486
+
487
+ # Configure Coridoc
488
+ #
489
+ # @yield [Configuration] Block receives configuration object
490
+ # @return [void]
491
+ def configure
492
+ yield configuration if block_given?
493
+ end
494
+
495
+ # Reset configuration to defaults
496
+ #
497
+ # @return [void]
498
+ def reset_configuration!
499
+ @configuration = Configuration.new
500
+ end
501
+
502
+ # Load configuration from file
503
+ #
504
+ # @param path [String] Path to configuration file
505
+ # @return [void]
506
+ def load_configuration(path)
507
+ config = Configuration.load_file(path)
508
+ configuration.merge!(config)
509
+ end
510
+ end
511
+ end
512
+
513
+ # Include Configurable in main module for easy access
514
+ extend Configurable
515
+
516
+ # Shortcut to configuration
517
+ #
518
+ # @return [Configuration]
519
+ def self.config
520
+ Configurable.configuration
521
+ end
522
+
523
+ # Shortcut to configure
524
+ #
525
+ # @yield [Configuration]
526
+ # @return [void]
527
+ def self.configure(&)
528
+ Configurable.configure(&) if block_given?
529
+ end
530
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ class AbstractBlock < Block
6
+ def self.semantic_type
7
+ :abstract
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coridoc
4
+ module CoreModel
5
+ # Specialized block for annotations and admonitions
6
+ #
7
+ # Represents annotation blocks that have special semantic meaning:
8
+ # - NOTE
9
+ # - WARNING
10
+ # - CAUTION
11
+ # - IMPORTANT
12
+ # - TIP
13
+ # - Reviewer notes
14
+ # - Sidebar blocks (when used for annotations)
15
+ #
16
+ # This class extends Block to add annotation-specific attributes that
17
+ # distinguish these blocks semantically from generic delimited blocks.
18
+ #
19
+ # @example Creating a NOTE annotation
20
+ # note = CoreModel::AnnotationBlock.new(
21
+ # annotation_type: "note",
22
+ # content: "This is important information."
23
+ # )
24
+ #
25
+ # @example Creating a reviewer note
26
+ # reviewer = CoreModel::AnnotationBlock.new(
27
+ # annotation_type: "reviewer",
28
+ # annotation_label: "john.doe",
29
+ # content: "Please review this section."
30
+ # )
31
+ class AnnotationBlock < Block
32
+ # @!attribute annotation_type
33
+ # @return [String, nil] the type of annotation
34
+ # (e.g., 'note', 'warning', 'reviewer', 'sidebar')
35
+ attribute :annotation_type, :string
36
+
37
+ # @!attribute annotation_label
38
+ # @return [String, nil] optional custom label or identifier
39
+ # (e.g., reviewer ID, custom note label)
40
+ attribute :annotation_label, :string
41
+
42
+ private
43
+
44
+ # Attributes to compare for semantic equivalence
45
+ #
46
+ # Annotation blocks are semantically different from generic blocks
47
+ # because they carry additional meaning through annotation_type and
48
+ # annotation_label. Two blocks with different annotation types are
49
+ # not semantically equivalent even if their content is identical.
50
+ #
51
+ # @return [Array<Symbol>] list of comparable attributes
52
+ def comparable_attributes
53
+ super + %i[annotation_type annotation_label]
54
+ end
55
+ end
56
+ end
57
+ end