Sha256: dff0a41c93dcd8863639145ce56da5e495dddce464992aa23c730eb4ce6ba43e

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

require 'fileutils'

module Polytrix
  module Runners
    module Middleware
      class SetupEnvVars
        include Polytrix::Core::FileSystemHelper

        def initialize(app)
          @app   = app
        end

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

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

        private

        def setup_env_vars(challenge_name, vars, challenge_runner)
          FileUtils.mkdir_p 'tmp'
          extension = challenge_runner.script_extension
          file = File.open(slugify("tmp/#{challenge_name}_vars.#{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

2 entries across 2 versions & 1 rubygems

Version Path
polytrix-0.1.0 lib/polytrix/runners/middleware/setup_env_vars.rb
polytrix-0.1.0.pre lib/polytrix/runners/middleware/setup_env_vars.rb