Sha256: 02ea61f191098b41ebc45e4ff5daf5b92a754406957c3fffdb5472bac3c86cba

Contents?: true

Size: 877 Bytes

Versions: 3

Compression:

Stored size: 877 Bytes

Contents

module Dotenv
  module Substitutions
    module Command
      class << self

        INTERPOLATED_SHELL_COMMAND = /
          (?<backslash>\\)?
          \$
          (?<cmd>             # collect command content for eval
            \(                # require opening paren
            ([^()]|\g<cmd>)+  # allow any number of non-parens, or balanced parens (by nesting the <cmd> expression recursively)
            \)                # require closing paren
          )
        /x

        def call(value, env)
          # Process interpolated shell commands
          value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
            command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses

            if $~[:backslash]
              $~[0][1..-1]
            else
              `#{command}`.chomp
            end
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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