Skip to content

Commit

Permalink
expand env vars on read not write
Browse files Browse the repository at this point in the history
  • Loading branch information
mcorino committed Jan 6, 2024
1 parent d7ce2fd commit 52626e3
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/wx/core/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def each_entry(&block)
if block_given?
data.select { |_,v| !v.is_a?(::Hash) }.each(&block)
else
::Enumerator.new { |y| data.each_pair { |k,v| y << [k,v] unless v.is_a?(::Hash) } }
::Enumerator.new { |y| data.each_pair { |k,v| y << [k, expand(v)] unless v.is_a?(::Hash) } }
end
end

Expand Down Expand Up @@ -387,7 +387,7 @@ def get(key)
if elem.is_a?(::Hash)
Group.new(self, self.path.dup.push(key))
else
elem
expand(elem)
end
end

Expand All @@ -408,7 +408,7 @@ def set(key, val)
group
else
raise ArgumentError, 'Cannot change existing group to value entry.' if exist && elem.is_a?(::Hash)
hsh[key] = sanitize(val)
hsh[key] = val
end
end

Expand Down Expand Up @@ -454,6 +454,7 @@ def read(path_str, output=nil)
raise TypeError, "Cannot convert group" unless output.nil?
Group.new(self, segments.dup.push(last))
else
val = expand(val)
return val unless val && output
case
when ::String == output || ::String === output
Expand Down Expand Up @@ -497,7 +498,7 @@ def write(path_str, val)
group
else
raise ArgumentError, 'Cannot change existing group to value entry.' if exist && elem.is_a?(::Hash)
group_data[last] = sanitize(val)
group_data[last] = val
end
end
alias :[]= :write
Expand All @@ -519,7 +520,7 @@ def get_path(path_str)
end
protected :get_path

def sanitize(val)
def expand(val)
if root.expanding_env_vars? && ::String === val
brackets = '{('
brackets << '%' if Wx::PLATFORM == 'WXMSW'
Expand All @@ -538,7 +539,7 @@ def sanitize(val)
end
val
end
protected :sanitize
protected :expand

end

Expand Down

0 comments on commit 52626e3

Please sign in to comment.