Module: ConfigVar
- Defined in:
- lib/configvar.rb,
lib/configvar/error.rb,
lib/configvar/context.rb,
lib/configvar/version.rb
Defined Under Namespace
Classes: ConfigError, Context
Constant Summary collapse
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.define(&blk) ⇒ Object
Define required and optional configuration variables and load them from the environment.
Class Method Details
.define(&blk) ⇒ Object
Define required and optional configuration variables and load them from the environment. Returns a configuration object that can be treated like a Hash with values available using lowercase symbols. For example, a PORT value from the environment can be accesses as config.port in the returned object. Booleans are only considered valid if they are one of ‘0’, ‘1’, ‘true’ or ‘false’. The values are case insensitive, so ‘TRUE’, ‘True’ and ‘TrUe’ are all valid booleans.
Example:
config = ConfigVar.define do
required_string :database_url
required_int :port
required_bool :enabled
optional_string :name, 'Bob'
optional_int :age, 42
optional_bool :friendly, true
end
20 21 22 23 24 25 |
# File 'lib/configvar.rb', line 20 def self.define(&blk) context = ConfigVar::Context.new context.instance_eval(&blk) context.reload(ENV) context end |