Module: Lutaml::Model::Config

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

Constant Summary collapse

AVAILABLE_FORMATS =
%i[xml json jsonl yaml toml hash].freeze
KEY_VALUE_FORMATS =
AVAILABLE_FORMATS - %i[xml]

Instance Method Summary collapse

Instance Method Details

#adapter_for(format) ⇒ Object



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

def adapter_for(format)
  @adapters[format]
end

#class_for(adapter, type) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/lutaml/model/config.rb', line 76

def class_for(adapter, type)
  # TODO: Remove once HashAdapter namespace is renamed to Hash
  adapter = "hash_adapter" if adapter == "hash"

  Lutaml::Model.const_get(to_class_name(adapter))
    .const_get(to_class_name(type))
end

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

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
# File 'lib/lutaml/model/config.rb', line 9

def configure
  yield self

  self
end

#default_registerObject



84
85
86
# File 'lib/lutaml/model/config.rb', line 84

def default_register
  @default_register ||= :default
end

#default_register=(value) ⇒ Object



88
89
90
91
92
93
94
95
# File 'lib/lutaml/model/config.rb', line 88

def default_register=(value)
  @default_register = case value
                      when Symbol then value
                      when Lutaml::Model::Register then value.id
                      else
                        raise "Unknown register: #{value}, expected a Symbol or a Lutaml::Model::Register instance"
                      end
end

#mappings_class_for(format) ⇒ Object



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

def mappings_class_for(format)
  Lutaml::Model::FormatRegistry.mappings_class_for(format)
end

#set_adapter_for(format, adapter) ⇒ Object



63
64
65
66
# File 'lib/lutaml/model/config.rb', line 63

def set_adapter_for(format, adapter)
  @adapters ||= {}
  @adapters[format] = adapter
end

#to_class_name(str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



98
99
100
# File 'lib/lutaml/model/config.rb', line 98

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

#transformer_for(format) ⇒ Object



72
73
74
# File 'lib/lutaml/model/config.rb', line 72

def transformer_for(format)
  Lutaml::Model::FormatRegistry.transformer_for(format)
end