lib/vault-tools/config.rb in vault-tools-0.5.4 vs lib/vault-tools/config.rb in vault-tools-0.5.5
- old
+ new
@@ -1,9 +1,51 @@
module Vault
module Config
@@defaults = {}
+ @@shared = {}
+ # Get a Config value
+ #
+ # This is the preferred and uniform way to access config vars because
+ # defaults and shared config are included in the lookup
+ #
+ # Uses defaults and shared if available. Converts upper-case ENV var names
+ # to lower-case default names.
+ #
+ # Order of precedence is:
+ # 1) app's local ENV
+ # 2) shared config vars
+ # 3) default values
+ #
+ # Config[:foo] == nil
+ #
+ # Config.default(:foo, 'bar')
+ # Config[:foo] == 'bar'
+ #
+ # ENV['FOO'] = 'baz'
+ # Config[:foo] == 'baz'
+ #
+ # @param key [Symbol] The lower-case name of the ENV value
+ # @return [String] The value of the ENV value or default.
+ def self.[](name)
+ var_name = name.to_s.upcase
+ default_name = name.to_s.downcase.to_sym
+ ENV[var_name] || @@shared[var_name] || @@defaults[default_name]
+ end
+
+ # Loads config from another app.
+ def self.load_shared!(app = nil)
+ heroku = Heroku::API.new
+ @@shared = heroku.get_config_vars(app).body
+ end
+
+ # Reset defaults and shared values
+ def self.reset!
+ @@defaults = {}
+ @@shared = {}
+ end
+
# An environment variable from another app.
#
# @param app [String] The name of the app to get the value from.
# @param name [String] The name of the environment variable to fetch a
# value for.
@@ -35,29 +77,9 @@
# Get all the defaults
# @return [Hash] The current set of defaults
def self.defaults
@@defaults
- end
-
- # Get a Config value
- # Uses defaults if available. Converts upper-case ENV var names
- # to lower-case default names.
- #
- # Config[:foo] == nil
- #
- # Config.default(:foo, 'bar')
- # Config[:foo] == 'bar'
- #
- # ENV['FOO'] = 'baz'
- # Config[:foo] == 'baz'
- #
- # @param key [Symbol] The lower-case name of the ENV value
- # @return [String] The value of the ENV value or default.
- def self.[](name)
- var_name = name.to_s.upcase
- default_name = name.to_s.downcase.to_sym
- ENV[var_name] || @@defaults[default_name]
end
# An environment variable.
#
# @param name [String] The name of the environment variable to fetch a