Sha256: 21cf6e545b7a30cbf666afd94985bbcf5e968085c9e9ceac16b2171514654721

Contents?: true

Size: 893 Bytes

Versions: 1

Compression:

Stored size: 893 Bytes

Contents

require 'fileutils'

module Polytrix
  module Runners
    module Middleware
      class SetupEnvVars
        def initialize(app)
          @app   = app
        end

        def call(env)
          challenge_runner = env[:challenge_runner]
          vars = begin
            Polytrix.manifest[:global_env].dup
          rescue
            {}
          end
          vars = vars.merge env[:vars].dup

          env[:env_file] = setup_env_vars(vars, challenge_runner)
          @app.call env
        end

        private

        def setup_env_vars(vars, challenge_runner)
          FileUtils.mkdir_p 'tmp'
          file = File.open("tmp/vars.#{challenge_runner.script_extension}", 'w')
          vars.each do |key, value|
            file.puts challenge_runner.save_environment_variable(key, value)
          end
          file.close
          file.path
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polytrix-0.0.1 lib/polytrix/runners/middleware/setup_env_vars.rb