Class: Transformers::LazyConfigMapping

Inherits:
Object
  • Object
show all
Defined in:
lib/transformers/models/auto/configuration_auto.rb

Instance Method Summary collapse

Constructor Details

#initialize(mapping) ⇒ LazyConfigMapping

Returns a new instance of LazyConfigMapping.



26
27
28
29
30
# File 'lib/transformers/models/auto/configuration_auto.rb', line 26

def initialize(mapping)
  @mapping = mapping
  @extra_content = {}
  @modules = {}
end

Instance Method Details

#[](key) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/transformers/models/auto/configuration_auto.rb', line 32

def [](key)
  value = @mapping.fetch(key)
  module_name = model_type_to_module_name(key)
  if !@modules.include?(module_name)
    @modules[module_name] = Transformers.const_get(module_name.split("-").map(&:capitalize).join)
  end
  @modules[module_name].const_get(value)
end

#model_type_to_module_name(key) ⇒ Object



41
42
43
# File 'lib/transformers/models/auto/configuration_auto.rb', line 41

def model_type_to_module_name(key)
  key
end