class Dpl::Interpolate::Interpolator
Constants
- ENV_VAR
- MODIFIER
- PATTERN
- UNKNOWN
- UPCASE
Public Instance Methods
Source
# File lib/dpl/helper/interpolate.rb, line 87 def apply str = interpolate(self.str.to_s) str = obfuscate(str) unless opts[:secure] str = str.gsub(' ', ' ') if str.lines.size == 1 str end
Source
# File lib/dpl/helper/interpolate.rb, line 94 def interpolate(str) str = str % args if args.is_a?(Array) && args.any? @blacklist_result = false str = str.to_s.gsub(PATTERN) do @blacklist_result = true normalize(lookup(::Regexp.last_match(1).to_sym)) end @blacklist_result || (args.is_a?(Array) && args.any? { |arg| arg.is_a?(String) && arg.blacklisted? }) ? str.blacklist : str end
Source
# File lib/dpl/helper/interpolate.rb, line 124 def lookup(key) if vars? && !var?(key) UNKNOWN % key elsif mod = modifier(key) key = key.to_s.sub("#{mod}d_", '') obj.send(mod, lookup(key)) elsif key.to_s =~ ENV_VAR ENV[key.to_s.sub('$', '')] elsif key.to_s =~ UPCASE && obj.class.const_defined?(key) obj.class.const_get(key) elsif args.is_a?(Hash) && args.key?(key) args[key] elsif obj.respond_to?(key, true) obj.send(key) else raise KeyError, key end end
Source
# File lib/dpl/helper/interpolate.rb, line 143 def modifier(key) MODIFIER.detect { |mod| key.to_s.start_with?("#{mod}d_") } end
Source
# File lib/dpl/helper/interpolate.rb, line 120 def normalize(obj) obj.is_a?(Array) ? obj.join(' ') : obj.to_s end
Source
# File lib/dpl/helper/interpolate.rb, line 104 def obfuscate(str) secrets(str).inject(str) do |str, secret| secret = secret.dup if secret.frozen? secret.blacklist if str.blacklisted? str.gsub(secret, super(secret)) end end
Calls superclass method
Dpl::Interpolate#obfuscate
Source
# File lib/dpl/helper/interpolate.rb, line 112 def secrets(str) return [] unless str.is_a?(String) && str.blacklisted? opts = obj.class.opts.select(&:secret?) secrets = opts.map { |opt| obj.opts[opt.name] }.compact secrets.select { |secret| str.include?(secret) } end
Source
# File lib/dpl/helper/interpolate.rb, line 147 def var?(key) vars.include?(key) end