Class: Lutaml::Model::Configuration
- Inherits:
-
Object
- Object
- Lutaml::Model::Configuration
- Defined in:
- lib/lutaml/model/configuration.rb
Overview
Single source of truth for Lutaml::Model configuration
Constant Summary collapse
- OPAL_RUNTIME =
Static defaults captured at boot. Use RuntimeCompatibility directly for per-call runtime checks that tests may stub.
Lutaml::Model::RuntimeCompatibility.opal?
- WINDOWS_PLATFORM =
Lutaml::Model::RuntimeCompatibility.windows?
- AVAILABLE_FORMATS =
Bootstrap format list for key-value adapters. NOTE: XML is NOT listed here — it registers dynamically via FormatRegistry.
%i[json jsonl yaml toml hash].freeze
- KEY_VALUE_FORMATS =
AVAILABLE_FORMATS- ADAPTERS =
Available key-value formats and their adapters. XML adapter metadata is registered dynamically via FormatRegistry when ‘require “lutaml/xml”` is called.
begin h = { json: { available: %i[standard standard_json multi_json oj], default: :standard, }, yaml: { available: %i[standard standard_yaml], default: :standard, }, toml: { available: OPAL_RUNTIME ? [] : %i[tomlib toml_rb], default: if OPAL_RUNTIME nil elsif WINDOWS_PLATFORM :toml_rb else :tomlib end, }, hash: { available: %i[standard standard_hash], default: :standard, }, jsonl: { available: %i[standard], default: :standard, }, yamls: { available: %i[standard], default: :standard, }, } h.freeze end
Instance Attribute Summary collapse
-
#adapter_types ⇒ Object
readonly
Returns the value of attribute adapter_types.
-
#default_register ⇒ Object
(also: #default_context_id)
Default register/context ID accessor.
Class Method Summary collapse
-
.windows_platform? ⇒ Boolean
Check if running on Windows platform.
Instance Method Summary collapse
-
#adapter_for(format) ⇒ Object
Dynamic accessor for adapter types.
-
#configure {|_self| ... } ⇒ Object
Configure the library using a block.
- #configured? ⇒ Boolean
-
#get_adapter(format) ⇒ Object
Get adapter class for a format.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#mappings_class_for(format) ⇒ Object
Mappings class for a format.
-
#reset! ⇒ Object
Reset configuration to defaults.
-
#set_adapter(format, adapter_type) ⇒ Object
Dynamic setter for adapter types with validation.
-
#to_h ⇒ Object
Get all current settings as a hash.
-
#transformer_for(format) ⇒ Object
Transformer for a format.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
66 67 68 69 70 71 |
# File 'lib/lutaml/model/configuration.rb', line 66 def initialize @adapter_types = {} @adapters = {} @default_register = :default @configured = false end |
Instance Attribute Details
#adapter_types ⇒ Object (readonly)
Returns the value of attribute adapter_types.
64 65 66 |
# File 'lib/lutaml/model/configuration.rb', line 64 def adapter_types @adapter_types end |
#default_register ⇒ Object Also known as: default_context_id
Default register/context ID accessor
124 125 126 |
# File 'lib/lutaml/model/configuration.rb', line 124 def default_register @default_register end |
Class Method Details
.windows_platform? ⇒ Boolean
Check if running on Windows platform
85 86 87 |
# File 'lib/lutaml/model/configuration.rb', line 85 def self.windows_platform? WINDOWS_PLATFORM end |
Instance Method Details
#adapter_for(format) ⇒ Object
Dynamic accessor for adapter types
90 91 92 |
# File 'lib/lutaml/model/configuration.rb', line 90 def adapter_for(format) @adapter_types[format.to_sym] end |
#configure {|_self| ... } ⇒ Object
Configure the library using a block
74 75 76 77 78 |
# File 'lib/lutaml/model/configuration.rb', line 74 def configure yield self if block_given? @configured = true self end |
#configured? ⇒ Boolean
80 81 82 |
# File 'lib/lutaml/model/configuration.rb', line 80 def configured? @configured end |
#get_adapter(format) ⇒ Object
Get adapter class for a format
142 143 144 |
# File 'lib/lutaml/model/configuration.rb', line 142 def get_adapter(format) @adapters[format.to_sym] end |
#mappings_class_for(format) ⇒ Object
Mappings class for a format
164 165 166 |
# File 'lib/lutaml/model/configuration.rb', line 164 def mappings_class_for(format) Lutaml::Model::FormatRegistry.mappings_class_for(format) end |
#reset! ⇒ Object
Reset configuration to defaults
147 148 149 150 151 152 |
# File 'lib/lutaml/model/configuration.rb', line 147 def reset! @adapter_types = {} @adapters = {} @default_register = :default @configured = false end |
#set_adapter(format, adapter_type) ⇒ Object
Dynamic setter for adapter types with validation
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/lutaml/model/configuration.rb', line 95 def set_adapter(format, adapter_type) format = format.to_sym adapter_type = adapter_type.to_sym validate_adapter!(format, adapter_type) @adapter_types[format] = adapter_type # Load the adapter immediately load_adapter(format, adapter_type) end |
#to_h ⇒ Object
Get all current settings as a hash
155 156 157 158 159 160 161 |
# File 'lib/lutaml/model/configuration.rb', line 155 def to_h { adapter_types: @adapter_types.dup, default_register: @default_register, configured: @configured, } end |
#transformer_for(format) ⇒ Object
Transformer for a format
169 170 171 |
# File 'lib/lutaml/model/configuration.rb', line 169 def transformer_for(format) Lutaml::Model::FormatRegistry.transformer_for(format) end |