Class: Shojiku::Env
- Inherits:
-
Object
- Object
- Shojiku::Env
- Defined in:
- lib/shojiku/env.rb
Overview
The one place this gem reads the environment.
A client is constructed with env: true (the default) or env: false,
and that single flag governs EVERY SHOJIKU_* lookup — the template root,
the font and locale directories, and the library path. One flag rather
than one per variable is the reference decision the other six SDKs mirror:
an application that wants a hermetic configuration wants all of it off,
and a per-variable set of knobs is a shape nobody can keep consistent
across seven languages.
Disabled lookups behave exactly as unset variables do, so calling code
has no second branch to get wrong.
Instance Method Summary collapse
-
#[](name) ⇒ Object
The variable's value, or nil when it is unset, blank, or lookups are off.
-
#initialize(enabled:, source: ENV) ⇒ Env
constructor
A new instance of Env.
-
#paths(name) ⇒ Object
A
PATH_SEPARATOR-separated variable as a list of directories, which is how every other tool in this family spells "several paths in one variable".
Constructor Details
#initialize(enabled:, source: ENV) ⇒ Env
Returns a new instance of Env.
16 17 18 19 |
# File 'lib/shojiku/env.rb', line 16 def initialize(enabled:, source: ENV) @enabled = enabled @source = source end |
Instance Method Details
#[](name) ⇒ Object
The variable's value, or nil when it is unset, blank, or lookups are off.
22 23 24 25 26 27 |
# File 'lib/shojiku/env.rb', line 22 def [](name) return nil unless @enabled value = @source[name] value if value && !value.empty? end |
#paths(name) ⇒ Object
A PATH_SEPARATOR-separated variable as a list of directories, which is
how every other tool in this family spells "several paths in one
variable".
32 33 34 35 36 37 |
# File 'lib/shojiku/env.rb', line 32 def paths(name) value = self[name] return [] unless value value.split(File::PATH_SEPARATOR).reject(&:empty?) end |