Class: Foreman::Env
- Inherits:
-
Object
- Object
- Foreman::Env
- Defined in:
- lib/foreman/env.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Env
constructor
A new instance of Env.
Constructor Details
#initialize(filename) ⇒ Env
Returns a new instance of Env.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/foreman/env.rb', line 7 def initialize(filename) @entries = File.read(filename).gsub("\r\n","\n").split("\n").inject({}) do |ax, line| if line =~ /\A([A-Za-z_0-9]+)=(.*)\z/ key = $1 case val = $2 # Remove single quotes when /\A'(.*)'\z/ then ax[key] = $1 # Remove double quotes and unescape string preserving newline characters when /\A"(.*)"\z/ then ax[key] = $1.gsub('\n', "\n").gsub(/\\(.)/, '\1') else ax[key] = val end end ax end end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
5 6 7 |
# File 'lib/foreman/env.rb', line 5 def entries @entries end |