Sha256: 9960480e979af838e42014e7d70341f63ca15a4f38951a0f41b58d0ff0af7845

Contents?: true

Size: 788 Bytes

Versions: 3

Compression:

Stored size: 788 Bytes

Contents

module Dotenv
  module Substitutions
    module Variable
      class << self

        VARIABLE = /
          (\\)?
          (\$)
          (              # collect braces with var for sub
            \{?          # allow brace wrapping
            ([A-Z0-9_]+) # match the variable
            \}?          # closing brace
          )
        /xi

        def call(value, env)
          # Process embedded variables
          value.scan(VARIABLE).each do |parts|
            if parts.first == '\\'
              replace = parts[1...-1].join('')
            else
              replace = env.fetch(parts.last) { ENV[parts.last] }
            end

            value = value.sub(parts[0...-1].join(''), replace || '')
          end

          value
        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dotenv-0.11.1 lib/dotenv/substitutions/variable.rb
dotenv-0.11.0 lib/dotenv/substitutions/variable.rb
dotenv-0.10.0 lib/dotenv/substitutions/variable.rb