Module: Vault::Config
- Defined in:
- lib/vault-tools/config.rb
Constant Summary collapse
- @@defaults =
{}
Class Method Summary collapse
-
.[](name) ⇒ String
Get a Config value Uses defaults if available.
-
.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.
-
.int(name) ⇒ Fixnum
An environment variable converted to a Fixnum.
-
.port ⇒ Fixnum
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. -
.remote_env(app, name) ⇒ String
An environment variable from another app.
-
.sidekiq_concurrency ⇒ Fixnum
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 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'
56 57 58 59 60 |
# File 'lib/vault-tools/config.rb', line 56 def self.[](name) var_name = name.to_s.upcase default_name = name.to_s.downcase.to_sym ENV[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.
101 102 103 |
# File 'lib/vault-tools/config.rb', line 101 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.
92 93 94 |
# File 'lib/vault-tools/config.rb', line 92 def self.app_name env("APP_NAME") end |
.array(name) ⇒ Array
Comma-separated words converted to an array.
145 146 147 |
# File 'lib/vault-tools/config.rb', line 145 def self.array(name) env(name).to_s.split(',') end |
.bool?(name) ⇒ bool
An environment variable converted to a bool.
154 155 156 |
# File 'lib/vault-tools/config.rb', line 154 def self.bool?(name) self[name] == 'true' end |
.database_url(kind = '') ⇒ Object
The database URL from the environment.
117 118 119 120 |
# File 'lib/vault-tools/config.rb', line 117 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]
32 33 34 |
# File 'lib/vault-tools/config.rb', line 32 def self.default(key, value) @@defaults[key.to_sym] = value end |
.defaults ⇒ Hash
Get all the defaults
38 39 40 |
# File 'lib/vault-tools/config.rb', line 38 def self.defaults @@defaults end |
.enable_ssl? ⇒ Bool
Enforce HTTPS connections in the web API?
125 126 127 |
# File 'lib/vault-tools/config.rb', line 125 def self.enable_ssl? !bool?('VAULT_TOOLS_DISABLE_SSL') end |
.env(name) ⇒ String
An environment variable.
23 24 25 |
# File 'lib/vault-tools/config.rb', line 23 def self.env(name) self[name] end |
.env!(name) ⇒ String
An environment variable.
68 69 70 |
# File 'lib/vault-tools/config.rb', line 68 def self.env!(name) self[name] || raise("missing #{name}") end |
.int(name) ⇒ Fixnum
An environment variable converted to a Fixnum.
135 136 137 |
# File 'lib/vault-tools/config.rb', line 135 def self.int(name) self[name] && self[name].to_i end |
.port ⇒ Fixnum
The port to listen on for web requests.
108 109 110 |
# File 'lib/vault-tools/config.rb', line 108 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.
76 77 78 |
# File 'lib/vault-tools/config.rb', line 76 def self.production? self['RACK_ENV'] == 'production' end |
.remote_env(app, name) ⇒ String
An environment variable from another app.
12 13 14 15 |
# File 'lib/vault-tools/config.rb', line 12 def self.remote_env(app, name) heroku = Heroku::API.new heroku.get_config_vars(app).body[name] end |
.sidekiq_concurrency ⇒ Fixnum
The number of threads to use in Sidekiq workers.
177 178 179 |
# File 'lib/vault-tools/config.rb', line 177 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.
84 85 86 |
# File 'lib/vault-tools/config.rb', line 84 def self.test? self['RACK_ENV'] == 'test' end |
.time(name) ⇒ Time
An environment variable converted to a time.
163 164 165 166 167 |
# File 'lib/vault-tools/config.rb', line 163 def self.time(name) if self[name] Time.parse(self[name]) rescue Time.utc(*self[name].split('-')) end end |
.uri(name) ⇒ Object
169 170 171 |
# File 'lib/vault-tools/config.rb', line 169 def self.uri(name) self[name] && URI.parse(self[name]) end |