Skip to content

Commit

Permalink
Covert string to symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
Manjunath committed Oct 10, 2021
1 parent 01d4796 commit cbf93ed
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/config/sources/env_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,22 @@ def __value(v)
if %w(true false).include? v
eval(v)
elsif v.strip =~ /^:[^:]/
v.parameterize.underscore.to_sym
convert_str_to_symbol(v)
else
Integer(v) rescue Float(v) rescue v
end
end

# Remove all special characters from a string before converting into a symbol
def convert_str_to_symbol(str)
str.
gsub(/[^a-z0-9\-_]+/i, "-").
gsub(/-{2,}/, "-").
gsub(/^-|-$/i, "").
downcase.
underscore.
to_sym
end
end
end
end

0 comments on commit cbf93ed

Please sign in to comment.