Class: AppEnv::Environment
- Inherits:
-
ActiveSupport::OrderedOptions
- Object
- ActiveSupport::OrderedOptions
- AppEnv::Environment
- Defined in:
- lib/appenv/environment.rb
Instance Method Summary collapse
-
#expand(&blk) ⇒ Object
You can use ‘expand` to add more values to the environment after initialization.
-
#initialize(file = '.env', &blk) ⇒ Environment
constructor
A new instance of Environment.
-
#set(property, &blk) ⇒ Object
If you are computing a complex value (say, a conditional one), you might like to set the value via a block.
Constructor Details
#initialize(file = '.env', &blk) ⇒ Environment
Returns a new instance of Environment.
3 4 5 6 7 |
# File 'lib/appenv/environment.rb', line 3 def initialize(file = '.env', &blk) super(&nil) @file = file (&blk) end |
Instance Method Details
#expand(&blk) ⇒ Object
You can use ‘expand` to add more values to the environment after initialization. eg:
# Create the environment:
@env = AppEnv::Environment.new('test/data/env') { |env, src|
env.var1 = src.var_one
}
# Later, expand it:
@env. { |env, src|
env.var2 = src.var_two
}
23 24 25 26 |
# File 'lib/appenv/environment.rb', line 23 def (&blk) source = _compile_source_env blk.call(self, source) end |
#set(property, &blk) ⇒ Object
If you are computing a complex value (say, a conditional one), you might like to set the value via a block. eg:
# Simple variable assignment:
env.var1 = src.var_one
# Variable assignment with `set`:
env.set(:var2) {
if abcd?
'xyz'
else
'foo'
end
}
44 45 46 |
# File 'lib/appenv/environment.rb', line 44 def set(property, &blk) self.send("#{property}=", blk.call) end |