Class: Smplkit::Config::ConfigEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/config/models.rb

Overview

Per-environment value overrides for a Config.

Read-only inspection container. Mutation is performed via Config‘s setters with environment: (e.g. cfg.set_string(“k”, “v”, environment: “production”)).

An override stores only the raw value; the declared type and description come from the base item, so an item’s type and description are ignored when an environment override is supplied.

Instance Method Summary collapse

Constructor Details

#initialize(values: nil) ⇒ ConfigEnvironment

Returns a new instance of ConfigEnvironment.

Parameters:

  • values (Hash{String => Object}, nil) (defaults to: nil)

    Initial overrides as a flat {key => raw_value} map. A legacy {key => {“value” => raw}} wrapper is unwrapped to the raw value.



61
62
63
64
65
66
67
68
69
70
# File 'lib/smplkit/config/models.rb', line 61

def initialize(values: nil)
  @values_raw = {}
  return unless values

  values.each do |k, v|
    # Tolerate a legacy +{ "value" => raw, "type" => t }+ wrapper in
    # case a caller passes the old shape; unwrap to the raw value.
    @values_raw[k] = v.is_a?(Hash) && v.key?("value") ? v["value"] : v
  end
end

Instance Method Details

#_replace_raw(values) ⇒ Object



90
91
92
# File 'lib/smplkit/config/models.rb', line 90

def _replace_raw(values)
  @values_raw = values
end

#valuesHash{String => Object}

Returns overrides as a plain Hash { “key” => raw_value }.

Returns:

  • (Hash{String => Object})

    A read-only shallow copy of the overrides.



76
77
78
# File 'lib/smplkit/config/models.rb', line 76

def values
  @values_raw.dup
end

#values_rawHash{String => Object}

Returns overrides as a plain Hash { “key” => raw_value }. Retained as a separate accessor for backward compatibility; identical to values now that env overrides are stored flat.

Returns:

  • (Hash{String => Object})

    A read-only shallow copy of the overrides.



86
87
88
# File 'lib/smplkit/config/models.rb', line 86

def values_raw
  @values_raw.dup
end