Sha256: ff1f6b3e1e4d70673e09594c00d734f05cda61fa72b8b5b6e4f64e798b3973cd

Contents?: true

Size: 670 Bytes

Versions: 3

Compression:

Stored size: 670 Bytes

Contents

# -*- encoding: utf-8 -*-

require "rack/env/version"

module Rack
  class Env

    def initialize(app, options = {})
      @app     = app
      @options = options
    end

    def call(env)
      set_env
      @app.call(env)
    end

    private
    def set_env
      if @options[:envfile]
        read_env_file(@options[:envfile])
      else
        read_env_file(default_env_file)
      end
    end

    def default_env_file
      ::File.join(Dir.getwd, '.env')
    end

    def read_env_file(envfile)
      ::File.readlines(envfile).each {|line|
        key, value = line.chomp.split('=')
        ENV[key] = value
      } if ::File.exist?(envfile)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-env-0.0.3 lib/rack/env.rb
rack-env-0.0.2 lib/rack/env.rb
rack-env-0.0.1 lib/rack/env.rb