Module: Vault::Config
- Defined in:
- lib/vault-tools/config.rb
Constant Summary collapse
- @@defaults =
{}
{}
Class Method Summary collapse
-
.[](name) ⇒ String
Get a Config value.
-
.app_deploy ⇒ String
The
APP_DEPLOY
env var is used to identify which deploy of the codebase is running in librato. -
.app_name ⇒ String
The
APP_NAME
env var is used to identify which codebase is running in librato. -
.array(name) ⇒ Array
Comma-separated words converted to an array.
-
.bool?(name) ⇒ bool
An environment variable converted to a bool.
-
.database_url(kind = '') ⇒ Object
The database URL from the environment.
-
.default(key, value) ⇒ String
Set a default Defaults are supplied when accessing via Config[:varname].
-
.defaults ⇒ Hash
Get all the defaults.
-
.enable_ssl? ⇒ Bool
Enforce HTTPS connections in the web API?.
-
.env(name) ⇒ String
An environment variable.
-
.env!(name) ⇒ String
An environment variable.
-
.fetch(name, fallback) ⇒ String
Return a fallback value if a given Config var is not set.
-
.int(name) ⇒ Integer
An environment variable converted to a Integer.
-
.port ⇒ Integer
The port to listen on for web requests.
-
.production? ⇒ Bool
The
RACK_ENV
environment variable is used to determine whether the service is in production mode or not. -
.reset! ⇒ Object
Reset defaults and shared values.
-
.sidekiq_concurrency ⇒ Integer
The number of threads to use in Sidekiq workers.
-
.test? ⇒ Bool
The
RACK_ENV
environment variable is used to determine whether the service is in test mode or not. -
.time(name) ⇒ Time
An environment variable converted to a time.
- .uri(name) ⇒ Object
Class Method Details
.[](name) ⇒ String
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'
29 30 31 32 33 |
# File 'lib/vault-tools/config.rb', line 29 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 |
.app_deploy ⇒ String
The APP_DEPLOY
env var is used to identify which deploy of the codebase is
running in librato. This usually matches the name of the environment such
as local, production, staging, etc.
105 106 107 |
# File 'lib/vault-tools/config.rb', line 105 def self.app_deploy env("APP_DEPLOY") end |
.app_name ⇒ String
The APP_NAME
env var is used to identify which codebase is
running in librato. This usually matches the name of the repository.
96 97 98 |
# File 'lib/vault-tools/config.rb', line 96 def self.app_name env("APP_NAME") end |
.array(name) ⇒ Array
Comma-separated words converted to an array.
149 150 151 |
# File 'lib/vault-tools/config.rb', line 149 def self.array(name) env(name).to_s.split(',') end |
.bool?(name) ⇒ bool
An environment variable converted to a bool.
158 159 160 |
# File 'lib/vault-tools/config.rb', line 158 def self.bool?(name) self[name] == 'true' end |
.database_url(kind = '') ⇒ Object
The database URL from the environment.
121 122 123 124 |
# File 'lib/vault-tools/config.rb', line 121 def self.database_url(kind = '') kind = "#{kind}_".upcase unless kind.empty? env!("#{kind}DATABASE_URL") end |
.default(key, value) ⇒ String
Set a default Defaults are supplied when accessing via Config[:varname]
56 57 58 |
# File 'lib/vault-tools/config.rb', line 56 def self.default(key, value) @@defaults[key.to_sym] = value end |
.defaults ⇒ Hash
Get all the defaults
62 63 64 |
# File 'lib/vault-tools/config.rb', line 62 def self.defaults @@defaults end |
.enable_ssl? ⇒ Bool
Enforce HTTPS connections in the web API?
129 130 131 |
# File 'lib/vault-tools/config.rb', line 129 def self.enable_ssl? !bool?('VAULT_TOOLS_DISABLE_SSL') end |
.env(name) ⇒ String
An environment variable.
47 48 49 |
# File 'lib/vault-tools/config.rb', line 47 def self.env(name) self[name] end |
.env!(name) ⇒ String
An environment variable.
72 73 74 |
# File 'lib/vault-tools/config.rb', line 72 def self.env!(name) self[name] || raise("missing #{name}") end |
.fetch(name, fallback) ⇒ String
Return a fallback value if a given Config var is not set
name param.
191 192 193 |
# File 'lib/vault-tools/config.rb', line 191 def self.fetch(name, fallback) self[name].nil? ? fallback : self[name] end |
.int(name) ⇒ Integer
An environment variable converted to a Integer.
139 140 141 |
# File 'lib/vault-tools/config.rb', line 139 def self.int(name) self[name] && self[name].to_i end |
.port ⇒ Integer
The port to listen on for web requests.
112 113 114 |
# File 'lib/vault-tools/config.rb', line 112 def self.port env!("PORT").to_i end |
.production? ⇒ Bool
The RACK_ENV
environment variable is used to determine whether the
service is in production mode or not.
80 81 82 |
# File 'lib/vault-tools/config.rb', line 80 def self.production? self['RACK_ENV'] == 'production' end |
.reset! ⇒ Object
Reset defaults and shared values
36 37 38 39 |
# File 'lib/vault-tools/config.rb', line 36 def self.reset! @@defaults = {} @@shared = {} end |
.sidekiq_concurrency ⇒ Integer
The number of threads to use in Sidekiq workers.
181 182 183 |
# File 'lib/vault-tools/config.rb', line 181 def self.sidekiq_concurrency int('SIDEKIQ_CONCURRENCY') || 25 end |
.test? ⇒ Bool
The RACK_ENV
environment variable is used to determine whether the
service is in test mode or not.
88 89 90 |
# File 'lib/vault-tools/config.rb', line 88 def self.test? self['RACK_ENV'] == 'test' end |
.time(name) ⇒ Time
An environment variable converted to a time.
167 168 169 170 171 |
# File 'lib/vault-tools/config.rb', line 167 def self.time(name) if self[name] Time.parse(self[name]) rescue Time.utc(*self[name].split('-')) end end |
.uri(name) ⇒ Object
173 174 175 |
# File 'lib/vault-tools/config.rb', line 173 def self.uri(name) self[name] && URI.parse(self[name]) end |