Module: Lutaml::Model::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/lutaml/model/config.rb

Overview

Configuration module - single entry point for all configuration.

Delegates adapter resolution to AdapterResolver and scoped overrides to AdapterScope. Keeps the configure block API for backward compatibility.

Constant Summary collapse

AVAILABLE_FORMATS =

Dynamic adapter type accessors for boot-time formats. Additional formats (xml, etc.) get their accessors registered via FormatRegistry.register which calls define_adapter_type_methods.

i[json jsonl yaml toml hash yamls].freeze
KEY_VALUE_FORMATS =
AVAILABLE_FORMATS

Instance Method Summary collapse

Instance Method Details

#adapter_for(format) ⇒ Class?

Get adapter class for a format using the full resolution chain.

Parameters:

  • format (Symbol)

    the format name

Returns:

  • (Class, nil)

    the adapter class or nil



59
60
61
# File 'lib/lutaml/model/config.rb', line 59

def adapter_for(format)
  AdapterResolver.adapter_for(format)
end

#available_formatsObject

Dynamic format discovery from FormatRegistry



13
14
15
# File 'lib/lutaml/model/config.rb', line 13

def available_formats
  FormatRegistry.formats
end

#configure {|instance| ... } ⇒ Object

Delegate configure to Configuration

Yields:



50
51
52
53
# File 'lib/lutaml/model/config.rb', line 50

def configure
  yield instance
  self
end

#conversion_cacheObject

Store used by classes that declare cache_conversions. Duck-typed: anything responding to #get(key) and #set(key, value). Defaults to a memory-backed Lutaml::Store::BasicStore when the lutaml-store gem is loaded; assign false to disable caching, or nil to return to auto-detection.



100
101
102
# File 'lib/lutaml/model/config.rb', line 100

def conversion_cache
  instance.conversion_cache
end

#conversion_cache=(store) ⇒ Object



104
105
106
# File 'lib/lutaml/model/config.rb', line 104

def conversion_cache=(store)
  instance.conversion_cache = store
end

#default_context_idObject



124
125
126
# File 'lib/lutaml/model/config.rb', line 124

def default_context_id
  instance.default_context_id
end

#default_context_id=(value) ⇒ Object



128
129
130
# File 'lib/lutaml/model/config.rb', line 128

def default_context_id=(value)
  instance.default_context_id = value
end

#default_registerObject



116
117
118
# File 'lib/lutaml/model/config.rb', line 116

def default_register
  instance.default_register
end

#default_register=(value) ⇒ Object



120
121
122
# File 'lib/lutaml/model/config.rb', line 120

def default_register=(value)
  instance.default_register = value
end

#define_adapter_type_methods(format) ⇒ Object

Define dynamic adapter type accessor methods for a format. Called by FormatRegistry.register when a new format is registered.

Defines two pairs of methods:

- #{format}_adapter / #{format}_adapter= — adapter class getter/setter
- #{format}_adapter_type / #{format}_adapter_type= — type name getter/setter

Parameters:

  • format (Symbol)

    the format name



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/lutaml/model/config.rb', line 140

def define_adapter_type_methods(format)
  return if method_defined?(:"#{format}_adapter_type=")

  # Adapter class getter (returns Class)
  define_method(:"#{format}_adapter") do
    AdapterResolver.adapter_for(format)
  end

  # Adapter class setter (accepts Class)
  define_method(:"#{format}_adapter=") do |adapter_klass|
    AdapterResolver.set_adapter_class(format, adapter_klass)
  end

  # Adapter type name setter (accepts Symbol like :nokogiri)
  define_method(:"#{format}_adapter_type=") do |type_name|
    AdapterResolver.set_adapter_type(format, type_name)
  end

  # Adapter type name getter (returns Symbol or nil)
  define_method(:"#{format}_adapter_type") do
    AdapterResolver.configured_type(format)
  end
end

#instanceObject

Singleton Configuration instance



23
24
25
# File 'lib/lutaml/model/config.rb', line 23

def instance
  @instance ||= Configuration.new
end

#key_value_formatsObject

Dynamic key-value format discovery from FormatRegistry



18
19
20
# File 'lib/lutaml/model/config.rb', line 18

def key_value_formats
  FormatRegistry.key_value_formats
end

#mappings_class_for(format) ⇒ Object



108
109
110
# File 'lib/lutaml/model/config.rb', line 108

def mappings_class_for(format)
  instance.mappings_class_for(format)
end

#set_adapter_for(format, adapter) ⇒ Object

Store a pre-resolved adapter class for a format.

Parameters:

  • format (Symbol)

    the format name

  • adapter (Class)

    the adapter class



67
68
69
# File 'lib/lutaml/model/config.rb', line 67

def set_adapter_for(format, adapter)
  AdapterResolver.set_adapter_class(format, adapter)
end

#to_class_name(str) ⇒ Object



164
165
166
# File 'lib/lutaml/model/config.rb', line 164

def to_class_name(str)
  str.to_s.split("_").map(&:capitalize).join
end

#transformer_for(format) ⇒ Object



112
113
114
# File 'lib/lutaml/model/config.rb', line 112

def transformer_for(format)
  instance.transformer_for(format)
end

#with_adapter(**overrides) { ... } ⇒ Object

Block-scoped adapter override (thread-safe).

Pushes adapter overrides onto a thread-local stack for the duration of the block. Restores previous state on exit.

Examples:

Testing with a specific adapter

Config.with_adapter(xml: :ox) do
  MyClass.from_xml(xml)  # Uses Ox
end

Library stacking

Config.with_adapter(xml: :nokogiri, toml: :tomlib) do
  MyModel.from_xml(data)
end

Parameters:

  • overrides (Hash{Symbol => Symbol})

    format => adapter type name

Yields:

  • block within which overrides are active

Returns:

  • (Object)

    the block's return value



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

def with_adapter(**overrides, &block)
  AdapterScope.with(overrides, &block)
end