Module: Foreman::Engine::Env
- Included in:
- Foreman::Engine, Foreman::Engine
- Defined in:
- lib/foreman/engine.rb
Instance Attribute Summary collapse
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
Instance Method Summary collapse
- #apply_environment! ⇒ Object
- #error(message) ⇒ Object
- #read_environment(filename) ⇒ Object
- #read_environment_files(filenames) ⇒ Object
Instance Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
201 202 203 |
# File 'lib/foreman/engine.rb', line 201 def environment @environment end |
Instance Method Details
#apply_environment! ⇒ Object
226 227 228 |
# File 'lib/foreman/engine.rb', line 226 def apply_environment! @environment.each { |k,v| ENV[k] = v } end |
#error(message) ⇒ Object
230 231 232 233 |
# File 'lib/foreman/engine.rb', line 230 def error() puts "ERROR: #{}" exit 1 end |
#read_environment(filename) ⇒ Object
215 216 217 218 219 220 221 222 223 224 |
# File 'lib/foreman/engine.rb', line 215 def read_environment(filename) return {} unless File.exists?(filename) File.read(filename).split("\n").inject({}) do |hash, line| if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/ hash[$1] = $2 end hash end end |
#read_environment_files(filenames) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/foreman/engine.rb', line 203 def read_environment_files(filenames) environment = {} (filenames || "").split(",").map(&:strip).each do |filename| error "No such file: #{filename}" unless File.exists?(filename) environment.merge!(read_environment(filename)) end environment.merge!(read_environment(".env")) unless filenames environment end |