Class: Prefab::ConfigValueUnwrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/prefab/config_value_unwrapper.rb

Class Method Summary collapse

Class Method Details

.unwrap(config_value, config_key, properties) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/prefab/config_value_unwrapper.rb', line 5

def self.unwrap(config_value, config_key, properties)
  return nil unless config_value

  case config_value.type
  when :int, :string, :double, :bool, :log_level
    config_value.public_send(config_value.type)
  when :string_list
    config_value.string_list.values
  when :weighted_values
    lookup_key = properties[Prefab::CriteriaEvaluator::LOOKUP_KEY]
    weights = config_value.weighted_values.weighted_values
    value = Prefab::WeightedValueResolver.new(weights, config_key, lookup_key).resolve
    unwrap(value.value, config_key, properties)
  else
    raise "Unknown type: #{config_value.type}"
  end
end