Class: Ucode::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ucode/config.rb

Overview

Single injection point for all ucode runtime configuration.

This is the ONLY place in the codebase that reads ENV directly. Every other class reads configuration through Ucode.configuration.

Tests inject fresh Config instances; production reads ENV once on first access via Ucode.configuration.

Constant Summary collapse

KNOWN_VERSIONS =
%w[15.0.0 15.1.0 16.0.0 17.0.0].freeze
DEFAULT_CACHE_ROOT =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ucode/config.rb', line 25

def initialize
  @cache_root = default_cache_root
  @output_dir = Pathname.new("./output")
  @default_version = "17.0.0"
  @known_versions = KNOWN_VERSIONS.dup
  @http_timeout = env_int("UCODE_HTTP_TIMEOUT", 30)
  @http_retries = env_int("UCODE_HTTP_RETRIES", 3)
  @pdf_renderer = :mutool
  @parallel_workers = env_int("UCODE_PARALLEL_WORKERS", 8)
  @ucd_base_url = "https://www.unicode.org/Public"
  @unihan_base_url = "https://www.unicode.org/Public"
  @charts_base_url = "https://www.unicode.org/charts/PDF"
  @listing_url = "https://www.unicode.org/Public/"
  @extracted_files = default_extracted_files
  @auxiliary_files = default_auxiliary_files
  @logger = Logger.new($stderr, level: Logger::WARN)
end

Instance Attribute Details

#auxiliary_filesObject

Returns the value of attribute auxiliary_files.



19
20
21
# File 'lib/ucode/config.rb', line 19

def auxiliary_files
  @auxiliary_files
end

#cache_rootObject

Returns the value of attribute cache_root.



19
20
21
# File 'lib/ucode/config.rb', line 19

def cache_root
  @cache_root
end

#charts_base_urlObject

Returns the value of attribute charts_base_url.



19
20
21
# File 'lib/ucode/config.rb', line 19

def charts_base_url
  @charts_base_url
end

#default_versionObject

Returns the value of attribute default_version.



19
20
21
# File 'lib/ucode/config.rb', line 19

def default_version
  @default_version
end

#extracted_filesObject

Returns the value of attribute extracted_files.



19
20
21
# File 'lib/ucode/config.rb', line 19

def extracted_files
  @extracted_files
end

#http_retriesObject

Returns the value of attribute http_retries.



19
20
21
# File 'lib/ucode/config.rb', line 19

def http_retries
  @http_retries
end

#http_timeoutObject

Returns the value of attribute http_timeout.



19
20
21
# File 'lib/ucode/config.rb', line 19

def http_timeout
  @http_timeout
end

#known_versionsObject

Returns the value of attribute known_versions.



19
20
21
# File 'lib/ucode/config.rb', line 19

def known_versions
  @known_versions
end

#listing_urlObject

Returns the value of attribute listing_url.



19
20
21
# File 'lib/ucode/config.rb', line 19

def listing_url
  @listing_url
end

#loggerObject

Logger shared by every subsystem (Fetch, Coordinator, Writer, …). Tests can swap to a StringIO logger to capture output.



45
46
47
# File 'lib/ucode/config.rb', line 45

def logger
  @logger
end

#output_dirObject

Returns the value of attribute output_dir.



19
20
21
# File 'lib/ucode/config.rb', line 19

def output_dir
  @output_dir
end

#parallel_workersObject

Returns the value of attribute parallel_workers.



19
20
21
# File 'lib/ucode/config.rb', line 19

def parallel_workers
  @parallel_workers
end

#pdf_rendererObject

Returns the value of attribute pdf_renderer.



19
20
21
# File 'lib/ucode/config.rb', line 19

def pdf_renderer
  @pdf_renderer
end

#ucd_base_urlObject

Returns the value of attribute ucd_base_url.



19
20
21
# File 'lib/ucode/config.rb', line 19

def ucd_base_url
  @ucd_base_url
end

#unihan_base_urlObject

Returns the value of attribute unihan_base_url.



19
20
21
# File 'lib/ucode/config.rb', line 19

def unihan_base_url
  @unihan_base_url
end

Instance Method Details

#known?(version) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/ucode/config.rb', line 51

def known?(version)
  known_versions.include?(version)
end