Sha256: 05429c83cb9d8adc600b886eef77bbf20c2af82b114ad38ee60fe7335f445ac4

Contents?: true

Size: 1.09 KB

Versions: 36

Compression:

Stored size: 1.09 KB

Contents

require 'fig/environment_variables'

module Fig; end;
module Fig::EnvironmentVariables; end

# Manager of a set of environment variables where the variable names are
# case-insensitive, e.g. on MS Windows.
class Fig::EnvironmentVariables::CaseInsensitive
  include Fig::EnvironmentVariables

  def [](key)
    return @variables[key_to_store_under(key)]
  end

  def []=(key, new_value)
    @variables[key_to_store_under(key)] = new_value

    return
  end

  def prepend_variable(key, new_value)
    existing_key = key_to_store_under(key)

    if existing_key
      assign_value_to_existing_key(existing_key, new_value)
    else
      @variables[key] = new_value
    end

    return
  end

  private

  def assign_value_to_existing_key(existing_key, new_value)
    current_value = @variables[existing_key]
    if current_value
      @variables[existing_key] = new_value + File::PATH_SEPARATOR + current_value
    else
      @variables[existing_key] = new_value
    end

    return
  end

  def key_to_store_under(key)
    return @variables.keys.detect(lambda {key}) {|stored| stored.downcase == key.downcase}
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
fig-1.23.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.22.1.beta.1 lib/fig/environment_variables/case_insensitive.rb
fig-1.22.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.21.1.beta.2 lib/fig/environment_variables/case_insensitive.rb
fig-1.21.1.beta.1 lib/fig/environment_variables/case_insensitive.rb
fig-1.21.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.20.1.beta.1 lib/fig/environment_variables/case_insensitive.rb
fig-1.20.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.19.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.18.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.17.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.16.1.beta.1 lib/fig/environment_variables/case_insensitive.rb
fig-1.16.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.15.1.beta.2 lib/fig/environment_variables/case_insensitive.rb
fig-1.15.1.beta.1 lib/fig/environment_variables/case_insensitive.rb
fig-1.15.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.14.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.13.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.12.0 lib/fig/environment_variables/case_insensitive.rb
fig-1.11.0 lib/fig/environment_variables/case_insensitive.rb