Skip to content

Commit

Permalink
Improve strip_component based on PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
reidmv committed Feb 25, 2021
1 parent 3f33dac commit 72057c9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/r10k/environment/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ def dirname
private

def derive_name(name, strip_component)
if strip_component == nil
unless strip_component.is_a?(String) || !strip_component
raise _('Improper configuration value given for strip_component setting in %{src} source. ' \
'Value must be a string, a /regex/, false, or omitted. Got "%{val}" (%{type})' \
% {src: @source, val: strip_component, type: strip_component.class})
end

if !strip_component
name
elsif %r{^/.*/$}.match(strip_component)
regex = Regexp.new(strip_component[1..-2])
Expand All @@ -82,10 +88,6 @@ def derive_name(name, strip_component)
else
name
end
rescue TypeError, NoMethodError
raise _('Improper configuration value given for strip_component setting in %{src} source. ' \
'Value must be a string, a /regex/, or omitted. Got "%{val}" (%{type})' \
% {src: @source, val: strip_component, type: strip_component.class})
end

def derive_prefix(source,prefix)
Expand Down

0 comments on commit 72057c9

Please sign in to comment.