Sha256: f889d4075cd817fd5526ccc824bca0349a9c6c7a128d23ea51919c17db814d59

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

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

          setup_env_vars(env[:name], vars, env[:challenge_runner])
          # 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)
          challenge_runner.env = vars.to_hash
          # 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.2 lib/polytrix/runners/middleware/setup_env_vars.rb
polytrix-0.1.1 lib/polytrix/runners/middleware/setup_env_vars.rb