pax_global_header00006660000000000000000000000064132675264400014523gustar00rootroot0000000000000052 comment=089e9bd9a7b4ad3dc99c4fae0f594219587d77f2 dotenv-2.4.0/000077500000000000000000000000001326752644000130255ustar00rootroot00000000000000dotenv-2.4.0/.github/000077500000000000000000000000001326752644000143655ustar00rootroot00000000000000dotenv-2.4.0/.github/issue_template.md000066400000000000000000000006221326752644000177320ustar00rootroot00000000000000### Steps to reproduce Tell us how to reproduce the issue. Show how you included dotenv (Gemfile). Paste your env using: ```bash $ env | grep MYVARIABLETOSHOW ``` **REMOVE ANY SENSITIVE INFORMATION FROM YOUR OUTPUT** ### Expected behavior Tell us what should happen ### Actual behavior Tell us what happens instead ### System configuration **dotenv version**: **Rails version**: **Ruby version**: dotenv-2.4.0/.github/stale.yml000066400000000000000000000012541326752644000162220ustar00rootroot00000000000000# Number of days of inactivity before an issue becomes stale daysUntilStale: 60 # Number of days of inactivity before a stale issue is closed daysUntilClose: 7 # Issues with these labels will never be considered stale exemptLabels: - pinned - security # Label to use when marking an issue as stale staleLabel: wontfix # Comment to post when marking an issue as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. # Comment to post when closing a stale issue. Set to `false` to disable closeComment: false dotenv-2.4.0/.gitignore000066400000000000000000000001241326752644000150120ustar00rootroot00000000000000*.gem *.rbc .bundle .config .ruby-version .yardoc Gemfile.lock tmp vendor .DS_Store dotenv-2.4.0/.rubocop.yml000066400000000000000000000005411326752644000152770ustar00rootroot00000000000000Lint/HandleExceptions: Exclude: - 'lib/dotenv/rails.rb' - 'lib/dotenv.rb' Style/Documentation: Exclude: - 'Rakefile' - 'lib/dotenv/version.rb' Style/FileName: Exclude: - 'lib/dotenv/rails-now.rb' - 'lib/dotenv-rails.rb' Style/HashSyntax: EnforcedStyle: 'ruby19' Style/StringLiterals: EnforcedStyle: 'double_quotes' dotenv-2.4.0/.travis.yml000066400000000000000000000004061326752644000151360ustar00rootroot00000000000000language: ruby rvm: - 2.5.0 - 2.4.1 - 2.3.4 - 2.2.7 - 2.1.10 - 2.0.0 before_install: - gem update --remote bundler - gem update --system sudo: false bundler_args: --without=guard notifications: disabled: true script: - bundle exec rake dotenv-2.4.0/Changelog.md000066400000000000000000000213771326752644000152500ustar00rootroot00000000000000# Changelog [Unreleased changes](https://github.com/bkeepers/dotenv/compare/v2.4.0...master) ## 2.4.0 - Apr 23, 2018 This release reverts `Parse multiline values` ([#318](https://github.com/bkeepers/dotenv/pull/318), [#329](https://github.com/bkeepers/dotenv/pull/329)) due to a parsing regression that was discovered after the last release ([#336](https://github.com/bkeepers/dotenv/issues/336), [#339](https://github.com/bkeepers/dotenv/issues/339), [#341](https://github.com/bkeepers/dotenv/issues/341)). [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.3.0...v2.4.0) ## 2.3.0 - Apr 19, 2018 * Skip over lines that don't set an envvars ([#291](https://github.com/bkeepers/dotenv/pull/291)) * Document the -f flag ([#310](https://github.com/bkeepers/dotenv/pull/310)) * Existing variable takes precendence when performing substitution ([#313](https://github.com/bkeepers/dotenv/pull/313)) * Parse multiline values ([#318](https://github.com/bkeepers/dotenv/pull/318), [#329](https://github.com/bkeepers/dotenv/pull/329)) * Fix load to respect existing environment variables over env file when doing variable interpolation ([#323](https://github.com/bkeepers/dotenv/pull/323)) * Add gem version badge to README.md ([#328](https://github.com/bkeepers/dotenv/pull/328)) * Rescue from bundler require error ([#330](https://github.com/bkeepers/dotenv/pull/330)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.2.2...v2.3.0) ## 2.2.2 - Apr 9, 2018 * Support Rails 5.2 ([#325](https://github.com/bkeepers/dotenv/pull/325)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.2.1...v2.2.2) ## 2.2.1 - Apr 28, 2017 * Support Rails 5.1 ([#299](https://github.com/bkeepers/dotenv/pull/299)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.2.0...v2.2.1) ## 2.2.0 - Jan 27, 2017 * Drop official support for Ruby 1.9, jruby, and Rubinius. They may continue to work, but tests are not run against them. ([#283](https://github.com/bkeepers/dotenv/pull/283)) * Allow leading and trailing whitespace ([#276](https://github.com/bkeepers/dotenv/pull/276), [#277](https://github.com/bkeepers/dotenv/pull/277)) * [dotenv-rails] Fix for rspec rake tasks initializing in development ([#241](https://github.com/bkeepers/dotenv/pull/241)) * [dotenv-rails] Allow a local file per environment, e.g. `.env.development.local` ([#281](https://github.com/bkeepers/dotenv/pull/281)) * [dotenv-rails] No longer load `.env.local` in rails' test environment ([#280](https://github.com/bkeepers/dotenv/pull/280)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.1.2...v2.2.0) ## 2.1.2 - Jan 16, 2017 * Fix parser to allow leading whitespace before variables ([#276](https://github.com/bkeepers/dotenv/pull/276)) * [dotenv-rails] Fix bug with `require "dotenv/rails-now"` in older versions of rails ([#269](https://github.com/bkeepers/dotenv/pull/269)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.1.1...v2.1.2) ## 2.1.1 - Mar 28, 2016 * Fix load error when using Spring w/ custom config ([#246](https://github.com/bkeepers/dotenv/pull/246)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.1.0...v2.1.1) ## 2.1.0 - Jan 13, 2016 * Relax dependency on `railties` to allow Rails 5.0 apps. ([#226](https://github.com/bkeepers/dotenv/pull/226)) * Fix scenario where some escaped `$` would not be unescaped. ([#222](https://github.com/bkeepers/dotenv/pull/222)) * Gracefully handle files with UTF-8 BOM ([#225](https://github.com/bkeepers/dotenv/pull/225)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.0.2...v2.1.0) ## 2.0.2 - June 19, 2015 * Support carriage returns in addition to newlines in .env ([#194](https://github.com/bkeepers/dotenv/pull/194)) * Add runtime dependency on rails 4 for dotenv-rails ([#189](https://github.com/bkeepers/dotenv/pull/189)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.0.1...v2.0.2) ## 2.0.1 - Apr 3, 2015 * Fix for expansion of escaped variables ([#181](https://github.com/bkeepers/dotenv/pull/181)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v2.0.0...v2.0.1) ## 2.0.0 - Mar 5, 2015 * `.env.local` and `.env.#{Rails.env}` will be automatically be loaded with the `dotenv-rails` gem. * Drop official support for Ruby 1.8.7 and REE. They may still continue to work, but will not be tested against. Lock to version "<= 1.1" if you are using Ruby 1.8. * `dotenv-rails` now only supports Rails 4. Manually configure dotenv if you are using Rails 3. * Support -f option to dotenv executable dotenv -f /path/to/.env,/path/to/another/.env * Fix issue calling `Dotenv::Railtie.load` in Rails 4.1 before application is defined (#155) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v1.0.2...v2.0.0) ## 1.0.2 - Oct 14, 2014 * Define `#load` on `Dotenv::Railtie`, which can be called to manually load `dotenv` before Rails has initialized. * add `dotenv/rails-now`, which can be required in the `Gemfile` to immediately load dotenv. gem 'dotenv-rails', require: 'dotenv/rails-now' gem 'gem-that-requires-env-variables' [Full Changelog](https://github.com/bkeepers/dotenv/compare/v1.0.1...v1.0.2) ## 1.0.1 - Oct 4, 2014 * Fix load error with Spring when running `rails server` ([#140](https://github.com/bkeepers/dotenv/issues/140)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v1.0.0...v1.0.1) ## 1.0.0 - Oct 3, 2014 * dotenv-rails is now loaded during the `before_configuration` callback, which is fired when the `Application` constant is defined (`class Application < Rails::Application`). * Remove deprecated features. Upgrade to 0.11.0 and fix deprecation warnings before upgrading to 1.0.0. * Watch .env for changes with Spring in Rails 4 ([#118](https://github.com/bkeepers/dotenv/pull/118)) * Fix deprecation warnings for `File.exists?` ([#121](https://github.com/bkeepers/dotenv/pull/121/)) * Use `Rails.root` to find `.env` ([#122](https://github.com/bkeepers/dotenv/pull/122/files)) * Avoid substitutions inside single quotes ([#124](https://github.com/bkeepers/dotenv/pull/124)) [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.11.1...v1.0.0) ## 0.11.1 - Apr 22, 2014 * Depend on dotenv-deployment ~>0.0.2, which fixes issues with 0.0.1 [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.11.0...v0.11.1) ## 0.11.0 - Apr 21, 2014 * Extract dotenv-deployment gem. https://github.com/bkeepers/dotenv-deployment [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.10.0...v0.11.0) ## 0.10.0 - Feb 22, 2014 * Add support for executing interpolated commands. (Ruby >= 1.9 only) HEAD_SHA=$(git rev-parse HEAD) * Add `dotenv_role` option in Capistrano. set :dotenv_role, [:app, web] * Add `Dotenv.overload` to overwrite existing environment values. [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.9.0...v0.10.0) ## 0.9.0 - Aug 29, 2013 * Add support for variable expansion. HOST="example.com" URL="http://${USER}@${HOST}" ESCAPED_VARIABLE="this is \$NOT replaced" * Allow setting variables without a value. BLANK= * Add `dotenv` executable to load `.env` for other scripts. $ dotenv ./script.py [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.8.0...v0.9.0) ## 0.8.0 - June 12, 2013 * Added a capistrano recipe to symlink in `.env` on deploy. * Allow inline comments VARIABLE=value # this is a comment * Raises Dotenv::FormatError when parsing fails [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.7.0...v0.8.0) ## 0.7.0 - April 15, 2013 * Remove deprectated autoloading. Upgrade to 0.6 first and fix any warnings. * Add Dotenv.load! which raises Errno::ENOENT if the file does not exist [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.6.0...v0.7.0) ## 0.6.0 - Mar 22, 2013 * Add dotenv-rails gem for autoloading in a Rails app * Deprecated autoloading with plain dotenv gem * Support for double quotes A="some value" B="with \"escaped\" quotes" C="and newline\n expansion" * Support for pow-style variables prefixed with export export VARIABLE="some value" [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.5.0...v0.6.0) ## 0.5.0 - Jan 25, 2013 * Load immediately on require in Rails instead of waiting for initialization * Add YAML-style variables VARIABLE: some value [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.4.0...v0.5.0) ## 0.4.0 - Nov 13, 2012 * Add support for quoted options, e.g.: VARIABLE='some value' * Fix rake deprecation warnings [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.3.0...v0.4.0) ## 0.3.0 - Oct 25, 2012 * Avoid overriding existing ENV variables so values set before loading the app are maintained. [Full Changelog](https://github.com/bkeepers/dotenv/compare/v0.2.0...v0.3.0) dotenv-2.4.0/Gemfile000066400000000000000000000010761326752644000143240ustar00rootroot00000000000000source "https://rubygems.org" gemspec name: "dotenv" gemspec name: "dotenv-rails" group :guard do gem "guard-rspec" gem "guard-bundler" gem "rb-fsevent" end platforms :rbx do gem "rubysl", "~> 2.0" # if using anything in the ruby standard library end if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.2") # Rack 2 requires Ruby version >= 2.2.2 gem "rack", ">= 1.6.5", "< 2.0.0" end if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.1.0") # Nokogiri 1.7 requires Ruby version >= 2.1.0. gem "nokogiri", ">= 1.6.8", "< 1.7.0" end dotenv-2.4.0/Guardfile000066400000000000000000000003521326752644000146520ustar00rootroot00000000000000guard "bundler" do watch("Gemfile") end guard "rspec", cmd: "bundle exec rspec" do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^spec/spec_helper.rb$}) { "spec" } watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } end dotenv-2.4.0/LICENSE000066400000000000000000000020571326752644000140360ustar00rootroot00000000000000Copyright (c) 2012 Brandon Keepers MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.dotenv-2.4.0/OWNERS000066400000000000000000000002011326752644000137560ustar00rootroot00000000000000# This project is maintained by: @bkeepers # For more information on the OWNERS file, see: # https://github.com/bkeepers/OWNERS dotenv-2.4.0/README.md000066400000000000000000000162561326752644000143160ustar00rootroot00000000000000# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv) [![Gem Version](https://badge.fury.io/rb/dotenv.svg)](https://badge.fury.io/rb/dotenv) [![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) Shim to load environment variables from `.env` into `ENV` in *development*. Storing [configuration in the environment](http://12factor.net/config) is one of the tenets of a [twelve-factor app](http://12factor.net). Anything that is likely to change between deployment environments–such as resource handles for databases or credentials for external services–should be extracted from the code into environment variables. But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. dotenv loads variables from a `.env` file into `ENV` when the environment is bootstrapped. ## Installation ### Rails Add this line to the top of your application's Gemfile: ```ruby gem 'dotenv-rails', groups: [:development, :test] ``` And then execute: ```shell $ bundle ``` #### Note on load order dotenv is initialized in your Rails app during the `before_configuration` callback, which is fired when the `Application` constant is defined in `config/application.rb` with `class Application < Rails::Application`. If you need it to be initialized sooner, you can manually call `Dotenv::Railtie.load`. ```ruby # config/application.rb Bundler.require(*Rails.groups) Dotenv::Railtie.load HOSTNAME = ENV['HOSTNAME'] ``` If you use gems that require environment variables to be set before they are loaded, then list `dotenv-rails` in the `Gemfile` before those other gems and require `dotenv/rails-now`. ```ruby gem 'dotenv-rails', require: 'dotenv/rails-now' gem 'gem-that-requires-env-variables' ``` ### Sinatra or Plain ol' Ruby Install the gem: ```shell $ gem install dotenv ``` As early as possible in your application bootstrap process, load `.env`: ```ruby require 'dotenv/load' # or require 'dotenv' Dotenv.load ``` By default, `load` will look for a file called `.env` in the current working directory. Pass in multiple files and they will be loaded in order. The first value set for a variable will win. ``` require 'dotenv' Dotenv.load('file1.env', 'file2.env') ``` Alternatively, you can use the `dotenv` executable to launch your application: ```shell $ dotenv ./script.rb ``` The `dotenv` executable also accepts a single flag, `-f`. Its value should be a comma-separated list of configuration files, in the order of most important to least. All of the files must exist. There _must_ be a space between the flag and its value. ``` $ dotenv -f ".env.local,.env" ./script.rb ``` To ensure `.env` is loaded in rake, load the tasks: ```ruby require 'dotenv/tasks' task mytask: :dotenv do # things that require .env end ``` ## Usage Add your application configuration to your `.env` file in the root of your project: ```shell S3_BUCKET=YOURS3BUCKET SECRET_KEY=YOURSECRETKEYGOESHERE ``` Whenever your application loads, these variables will be available in `ENV`: ```ruby config.fog_directory = ENV['S3_BUCKET'] ``` You may also add `export` in front of each line so you can `source` the file in bash: ```shell export S3_BUCKET=YOURS3BUCKET export SECRET_KEY=YOURSECRETKEYGOESHERE ``` ### Multi-line values If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines: ```shell PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9…\n-----END DSA PRIVATE KEY-----\n" ``` ### Command Substitution You need to add the output of a command in one of your variables? Simply add it with `$(your_command)`: ```shell DATABASE_URL="postgres://$(whoami)@localhost/my_database" ``` ### Variable Substitution You need to add the value of another variable in one of your variables? You can reference the variable with `${VAR}` or often just `$VAR` in unqoted or double-quoted values. ```shell DATABASE_URL="postgres://${USER}@localhost/my_database" ``` If a value contains a `$` and it is not intended to be a variable, wrap it in single quotes. ```shell PASSWORD='pas$word' ``` ### Comments Comments may be added to your file as such: ```shell # This is a comment SECRET_KEY=YOURSECRETKEYGOESHERE # comment SECRET_HASH="something-with-a-#-hash" ``` ## Frequently Answered Questions ### Can I use dotenv in production? dotenv was originally created to load configuration variables into `ENV` in *development*. There are typically better ways to manage configuration in production environments - such as `/etc/environment` managed by [Puppet](https://github.com/puppetlabs/puppet) or [Chef](https://github.com/chef/chef), `heroku config`, etc. However, some find dotenv to be a convenient way to configure Rails applications in staging and production environments, and you can do that by defining environment-specific files like `.env.production` or `.env.test`. If you use this gem to handle env vars for multiple Rails environments (development, test, production, etc.), please note that env vars that are general to all environments should be stored in `.env`. Then, environment specific env vars should be stored in `.env.`. ### What other .env* files can I use? `dotenv-rails` will load the following files, starting from the bottom. The first value set (or those already defined in the environment) take precedence: - `.env` - The Original® - `.env.development`, `.env.test`, `.env.production` - Environment-specific settings. - `.env.local` - Local overrides. This file is loaded for all environments _except_ `test`. - `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings. ### Should I commit my .env file? Credentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server. Personally, I prefer to commit the `.env` file with development-only settings. This makes it easy for other developers to get started on the project without compromising credentials for other environments. If you follow this advice, make sure that all the credentials for your development environment are different from your other deployments and that the development credentials do not have access to any confidential data. ### Why is it not overriding existing `ENV` variables? By default, it **won't** overwrite existing environment variables as dotenv assumes the deployment environment has more knowledge about configuration than the application does. To overwrite existing environment variables you can use `Dotenv.overload`. ## Contributing If you want a better idea of how dotenv works, check out the [Ruby Rogues Code Reading of dotenv](https://www.youtube.com/watch?v=lKmY_0uY86s). 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request dotenv-2.4.0/Rakefile000066400000000000000000000013521326752644000144730ustar00rootroot00000000000000#!/usr/bin/env rake require "bundler/gem_helper" namespace "dotenv" do Bundler::GemHelper.install_tasks name: "dotenv" end namespace "dotenv-rails" do class DotenvRailsGemHelper < Bundler::GemHelper def guard_already_tagged; end # noop def tag_version; end # noop end DotenvRailsGemHelper.install_tasks name: "dotenv-rails" end task build: ["dotenv:build", "dotenv-rails:build"] task install: ["dotenv:install", "dotenv-rails:install"] task release: ["dotenv:release", "dotenv-rails:release"] require "rspec/core/rake_task" desc "Run all specs" RSpec::Core::RakeTask.new(:spec) do |t| t.rspec_opts = %w(--color) t.verbose = false end require "rubocop/rake_task" RuboCop::RakeTask.new task default: [:spec, :rubocop] dotenv-2.4.0/bin/000077500000000000000000000000001326752644000135755ustar00rootroot00000000000000dotenv-2.4.0/bin/dotenv000077500000000000000000000001041326752644000150150ustar00rootroot00000000000000#!/usr/bin/env ruby require "dotenv/cli" Dotenv::CLI.new(ARGV).run dotenv-2.4.0/dotenv-rails.gemspec000066400000000000000000000012121326752644000167750ustar00rootroot00000000000000require File.expand_path("../lib/dotenv/version", __FILE__) require "English" Gem::Specification.new "dotenv-rails", Dotenv::VERSION do |gem| gem.authors = ["Brandon Keepers"] gem.email = ["brandon@opensoul.org"] gem.description = gem.summary = "Autoload dotenv in Rails." gem.homepage = "https://github.com/bkeepers/dotenv" gem.license = "MIT" gem.files = `git ls-files lib | grep rails`.split( $OUTPUT_RECORD_SEPARATOR ) + ["README.md", "LICENSE"] gem.add_dependency "dotenv", Dotenv::VERSION gem.add_dependency "railties", ">= 3.2", "< 6.0" gem.add_development_dependency "spring" end dotenv-2.4.0/dotenv.gemspec000066400000000000000000000013601326752644000156710ustar00rootroot00000000000000require File.expand_path("../lib/dotenv/version", __FILE__) require "English" Gem::Specification.new "dotenv", Dotenv::VERSION do |gem| gem.authors = ["Brandon Keepers"] gem.email = ["brandon@opensoul.org"] gem.description = gem.summary = "Loads environment variables from `.env`." gem.homepage = "https://github.com/bkeepers/dotenv" gem.license = "MIT" gem_files = `git ls-files README.md LICENSE lib bin | grep -v rails` gem.files = gem_files.split($OUTPUT_RECORD_SEPARATOR) gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } gem.add_development_dependency "rake" gem.add_development_dependency "rspec" gem.add_development_dependency "rubocop", "~>0.40.0" end dotenv-2.4.0/lib/000077500000000000000000000000001326752644000135735ustar00rootroot00000000000000dotenv-2.4.0/lib/dotenv-rails.rb000066400000000000000000000000271326752644000165260ustar00rootroot00000000000000require "dotenv/rails" dotenv-2.4.0/lib/dotenv.rb000066400000000000000000000026731326752644000154270ustar00rootroot00000000000000require "dotenv/parser" require "dotenv/environment" # The top level Dotenv module. The entrypoint for the application logic. module Dotenv class << self attr_accessor :instrumenter end module_function def load(*filenames) with(*filenames) do |f| ignoring_nonexistent_files do env = Environment.new(f, true) instrument("dotenv.load", env: env) { env.apply } end end end # same as `load`, but raises Errno::ENOENT if any files don't exist def load!(*filenames) with(*filenames) do |f| env = Environment.new(f, true) instrument("dotenv.load", env: env) { env.apply } end end # same as `load`, but will override existing values in `ENV` def overload(*filenames) with(*filenames) do |f| ignoring_nonexistent_files do env = Environment.new(f, false) instrument("dotenv.overload", env: env) { env.apply! } end end end # Internal: Helper to expand list of filenames. # # Returns a hash of all the loaded environment variables. def with(*filenames) filenames << ".env" if filenames.empty? filenames.reduce({}) do |hash, filename| hash.merge!(yield(File.expand_path(filename)) || {}) end end def instrument(name, payload = {}, &block) if instrumenter instrumenter.instrument(name, payload, &block) else yield end end def ignoring_nonexistent_files yield rescue Errno::ENOENT end end dotenv-2.4.0/lib/dotenv/000077500000000000000000000000001326752644000150725ustar00rootroot00000000000000dotenv-2.4.0/lib/dotenv/cli.rb000066400000000000000000000013071326752644000161670ustar00rootroot00000000000000require "dotenv" module Dotenv # The CLI is a class responsible of handling all the command line interface # logic. class CLI attr_reader :argv def initialize(argv = []) @argv = argv.dup end def run filenames = parse_filenames || [] begin Dotenv.load!(*filenames) rescue Errno::ENOENT => e abort e.message else exec(*argv) unless argv.empty? end end private def parse_filenames pos = argv.index("-f") return nil unless pos # drop the -f argv.delete_at pos # parse one or more comma-separated .env files require "csv" CSV.parse_line argv.delete_at(pos) end end end dotenv-2.4.0/lib/dotenv/environment.rb000066400000000000000000000010541326752644000177630ustar00rootroot00000000000000module Dotenv # This class inherits from Hash and represents the environment into which # Dotenv will load key value pairs from a file. class Environment < Hash attr_reader :filename def initialize(filename, is_load) @filename = filename load(is_load) end def load(is_load) update Parser.call(read, is_load) end def read File.open(@filename, "rb:bom|utf-8", &:read) end def apply each { |k, v| ENV[k] ||= v } end def apply! each { |k, v| ENV[k] = v } end end end dotenv-2.4.0/lib/dotenv/load.rb000066400000000000000000000000351326752644000163340ustar00rootroot00000000000000require "dotenv" Dotenv.load dotenv-2.4.0/lib/dotenv/parser.rb000066400000000000000000000044441326752644000167210ustar00rootroot00000000000000require "dotenv/substitutions/variable" require "dotenv/substitutions/command" if RUBY_VERSION > "1.8.7" module Dotenv class FormatError < SyntaxError; end # This class enables parsing of a string for key value pairs to be returned # and stored in the Environment. It allows for variable substitutions and # exporting of variables. class Parser @substitutions = [Dotenv::Substitutions::Variable, Dotenv::Substitutions::Command] LINE = / \A \s* (?:export\s+)? # optional export ([\w\.]+) # key (?:\s*=\s*|:\s+?) # separator ( # optional value begin '(?:\'|[^'])*' # single quoted value | # or "(?:\"|[^"])*" # double quoted value | # or [^#\n]+ # unquoted value )? # value end \s* (?:\#.*)? # optional comment \z /x class << self attr_reader :substitutions def call(string, is_load = false) new(string, is_load).call end end def initialize(string, is_load = false) @string = string @hash = {} @is_load = is_load end def call @string.split(/[\n\r]+/).each do |line| parse_line(line) end @hash end private def parse_line(line) if (match = line.match(LINE)) key, value = match.captures @hash[key] = parse_value(value || "") elsif line.split.first == "export" if variable_not_set?(line) raise FormatError, "Line #{line.inspect} has an unset variable" end end end def parse_value(value) # Remove surrounding quotes value = value.strip.sub(/\A(['"])(.*)\1\z/, '\2') if Regexp.last_match(1) == '"' value = unescape_characters(expand_newlines(value)) end if Regexp.last_match(1) != "'" self.class.substitutions.each do |proc| value = proc.call(value, @hash, @is_load) end end value end def unescape_characters(value) value.gsub(/\\([^$])/, '\1') end def expand_newlines(value) value.gsub('\n', "\n").gsub('\r', "\r") end def variable_not_set?(line) !line.split[1..-1].all? { |var| @hash.member?(var) } end end end dotenv-2.4.0/lib/dotenv/rails-now.rb000066400000000000000000000005201326752644000173270ustar00rootroot00000000000000# If you use gems that require environment variables to be set before they are # loaded, then list `dotenv-rails` in the `Gemfile` before those other gems and # require `dotenv/rails-now`. # # gem "dotenv-rails", require: "dotenv/rails-now" # gem "gem-that-requires-env-variables" # require "dotenv/rails" Dotenv::Railtie.load dotenv-2.4.0/lib/dotenv/rails.rb000066400000000000000000000041011326752644000165250ustar00rootroot00000000000000require "dotenv" # Fix for rspec rake tasks loading in development # # Dotenv loads environment variables when the Rails application is initialized. # When running `rake`, the Rails application is initialized in development. # Rails includes some hacks to set `RAILS_ENV=test` when running `rake test`, # but rspec does not include the same hacks. # # See https://github.com/bkeepers/dotenv/issues/219 if defined?(Rake.application) is_running_specs = Rake.application.top_level_tasks.grep(/^spec(:|$)/).any? Rails.env = ENV["RAILS_ENV"] ||= "test" if is_running_specs end Dotenv.instrumenter = ActiveSupport::Notifications # Watch all loaded env files with Spring begin require "spring/commands" ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args| event = ActiveSupport::Notifications::Event.new(*args) Spring.watch event.payload[:env].filename if Rails.application end rescue LoadError, ArgumentError # Spring is not available end module Dotenv # Dotenv Railtie for using Dotenv to load environment from a file into # Rails applications class Railtie < Rails::Railtie # Public: Load dotenv # # This will get called during the `before_configuration` callback, but you # can manually call `Dotenv::Railtie.load` if you needed it sooner. def load Dotenv.load(*dotenv_files) end # Internal: `Rails.root` is nil in Rails 4.1 before the application is # initialized, so this falls back to the `RAILS_ROOT` environment variable, # or the current working directory. def root Rails.root || Pathname.new(ENV["RAILS_ROOT"] || Dir.pwd) end # Rails uses `#method_missing` to delegate all class methods to the # instance, which means `Kernel#load` gets called here. We don't want that. def self.load instance.load end config.before_configuration { load } private def dotenv_files [ root.join(".env.#{Rails.env}.local"), (root.join(".env.local") unless Rails.env.test?), root.join(".env.#{Rails.env}"), root.join(".env") ].compact end end end dotenv-2.4.0/lib/dotenv/substitutions/000077500000000000000000000000001326752644000200315ustar00rootroot00000000000000dotenv-2.4.0/lib/dotenv/substitutions/command.rb000066400000000000000000000024111326752644000217720ustar00rootroot00000000000000require "English" module Dotenv module Substitutions # Substitute shell commands in a value. # # SHA=$(git rev-parse HEAD) # module Command class << self INTERPOLATED_SHELL_COMMAND = / (?\\)? # is it escaped with a backslash? \$ # literal $ (? # collect command content for eval \( # require opening paren ([^()]|\g)+ # allow any number of non-parens, or balanced # parens (by nesting the expression # recursively) \) # require closing paren ) /x def call(value, _env, _is_load) # Process interpolated shell commands value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| # Eliminate opening and closing parentheses command = $LAST_MATCH_INFO[:cmd][1..-2] if $LAST_MATCH_INFO[:backslash] # Command is escaped, don't replace it. $LAST_MATCH_INFO[0][1..-1] else # Execute the command and return the value `#{command}`.chomp end end end end end end end dotenv-2.4.0/lib/dotenv/substitutions/variable.rb000066400000000000000000000022331326752644000221430ustar00rootroot00000000000000require "English" module Dotenv module Substitutions # Substitute variables in a value. # # HOST=example.com # URL="https://$HOST" # module Variable class << self VARIABLE = / (\\)? # is it escaped with a backslash? (\$) # literal $ (?!\() # shouldnt be followed by paranthesis \{? # allow brace wrapping ([A-Z0-9_]+)? # optional alpha nums \}? # closing brace /xi def call(value, env, is_load) combined_env = if is_load env.merge(ENV) else ENV.to_h.merge(env) end value.gsub(VARIABLE) do |variable| match = $LAST_MATCH_INFO substitute(match, variable, combined_env) end end private def substitute(match, variable, env) if match[1] == '\\' variable[1..-1] elsif match[3] env.fetch(match[3], "") else variable end end end end end end dotenv-2.4.0/lib/dotenv/tasks.rb000066400000000000000000000001731326752644000165450ustar00rootroot00000000000000desc "Load environment settings from .env" task :dotenv do require "dotenv" Dotenv.load end task environment: :dotenv dotenv-2.4.0/lib/dotenv/version.rb000066400000000000000000000000551326752644000171040ustar00rootroot00000000000000module Dotenv VERSION = "2.4.0".freeze end dotenv-2.4.0/spec/000077500000000000000000000000001326752644000137575ustar00rootroot00000000000000dotenv-2.4.0/spec/dotenv/000077500000000000000000000000001326752644000152565ustar00rootroot00000000000000dotenv-2.4.0/spec/dotenv/cli_spec.rb000066400000000000000000000022661326752644000173720ustar00rootroot00000000000000require "spec_helper" require "dotenv/cli" describe "dotenv binary" do before do Dir.chdir(File.expand_path("../../fixtures", __FILE__)) end def run(*args) Dotenv::CLI.new(args).run end it "loads from .env by default" do expect(ENV).not_to have_key("DOTENV") run expect(ENV).to have_key("DOTENV") end it "loads from file specified by -f" do expect(ENV).not_to have_key("OPTION_A") run "-f", "plain.env" expect(ENV).to have_key("OPTION_A") end it "dies if file specified by -f doesn't exist" do expect do capture_output { run "-f", ".doesnotexist" } end.to raise_error(SystemExit, /No such file/) end it "loads from multiple files specified by -f" do expect(ENV).not_to have_key("PLAIN") expect(ENV).not_to have_key("QUOTED") run "-f", "plain.env,quoted.env" expect(ENV).to have_key("PLAIN") expect(ENV).to have_key("QUOTED") end # Capture output to $stdout and $stderr def capture_output(&_block) original_stderr = $stderr original_stdout = $stdout output = $stderr = $stdout = StringIO.new yield $stderr = original_stderr $stdout = original_stdout output.string end end dotenv-2.4.0/spec/dotenv/environment_spec.rb000066400000000000000000000022541326752644000211640ustar00rootroot00000000000000require "spec_helper" describe Dotenv::Environment do subject { env("OPTION_A=1\nOPTION_B=2") } describe "initialize" do it "reads the file" do expect(subject["OPTION_A"]).to eq("1") expect(subject["OPTION_B"]).to eq("2") end it "fails if file does not exist" do expect do Dotenv::Environment.new(".does_not_exists", true) end.to raise_error(Errno::ENOENT) end end describe "apply" do it "sets variables in ENV" do subject.apply expect(ENV["OPTION_A"]).to eq("1") end it "does not override defined variables" do ENV["OPTION_A"] = "predefined" subject.apply expect(ENV["OPTION_A"]).to eq("predefined") end end describe "apply!" do it "sets variables in the ENV" do subject.apply! expect(ENV["OPTION_A"]).to eq("1") end it "overrides defined variables" do ENV["OPTION_A"] = "predefined" subject.apply! expect(ENV["OPTION_A"]).to eq("1") end end require "tempfile" def env(text) file = Tempfile.new("dotenv") file.write text file.close env = Dotenv::Environment.new(file.path, true) file.unlink env end end dotenv-2.4.0/spec/dotenv/parser_spec.rb000066400000000000000000000150131326752644000201110ustar00rootroot00000000000000require "spec_helper" describe Dotenv::Parser do def env(string) Dotenv::Parser.call(string, true) end it "parses unquoted values" do expect(env("FOO=bar")).to eql("FOO" => "bar") end it "parses values with spaces around equal sign" do expect(env("FOO =bar")).to eql("FOO" => "bar") expect(env("FOO= bar")).to eql("FOO" => "bar") end it "parses values with leading spaces" do expect(env(" FOO=bar")).to eql("FOO" => "bar") end it "parses values with following spaces" do expect(env("FOO=bar ")).to eql("FOO" => "bar") end it "parses double quoted values" do expect(env('FOO="bar"')).to eql("FOO" => "bar") end it "parses double quoted values with following spaces" do expect(env('FOO="bar" ')).to eql("FOO" => "bar") end it "parses single quoted values" do expect(env("FOO='bar'")).to eql("FOO" => "bar") end it "parses single quoted values with following spaces" do expect(env("FOO='bar' ")).to eql("FOO" => "bar") end it "parses escaped double quotes" do expect(env('FOO="escaped\"bar"')).to eql("FOO" => 'escaped"bar') end it "parses empty values" do expect(env("FOO=")).to eql("FOO" => "") end it "expands variables found in values" do expect(env("FOO=test\nBAR=$FOO")).to eql("FOO" => "test", "BAR" => "test") end it "parses variables wrapped in brackets" do expect(env("FOO=test\nBAR=${FOO}bar")) .to eql("FOO" => "test", "BAR" => "testbar") end it "expands variables from ENV if not found in .env" do ENV["FOO"] = "test" expect(env("BAR=$FOO")).to eql("BAR" => "test") end it "expands variables from ENV if found in .env during load" do ENV["FOO"] = "test" expect(env("FOO=development\nBAR=${FOO}")["BAR"]) .to eql("test") end it "doesn't expand variables from ENV if in local env in overload" do ENV["FOO"] = "test" expect(env("FOO=development\nBAR=${FOO}")["BAR"]) .to eql("test") end it "expands undefined variables to an empty string" do expect(env("BAR=$FOO")).to eql("BAR" => "") end it "expands variables in double quoted strings" do expect(env("FOO=test\nBAR=\"quote $FOO\"")) .to eql("FOO" => "test", "BAR" => "quote test") end it "does not expand variables in single quoted strings" do expect(env("BAR='quote $FOO'")).to eql("BAR" => "quote $FOO") end it "does not expand escaped variables" do expect(env('FOO="foo\$BAR"')).to eql("FOO" => "foo$BAR") expect(env('FOO="foo\${BAR}"')).to eql("FOO" => "foo${BAR}") expect(env("FOO=test\nBAR=\"foo\\${FOO} ${FOO}\"")) .to eql("FOO" => "test", "BAR" => "foo${FOO} test") end it "parses yaml style options" do expect(env("OPTION_A: 1")).to eql("OPTION_A" => "1") end it "parses export keyword" do expect(env("export OPTION_A=2")).to eql("OPTION_A" => "2") end it "allows export line if you want to do it that way" do expect(env('OPTION_A=2 export OPTION_A')).to eql("OPTION_A" => "2") end it "allows export line if you want to do it that way and checks for unset"\ " variables" do expect do env('OPTION_A=2 export OH_NO_NOT_SET') end.to raise_error(Dotenv::FormatError, 'Line "export OH_NO_NOT_SET"'\ " has an unset variable") end it "expands newlines in quoted strings" do expect(env('FOO="bar\nbaz"')).to eql("FOO" => "bar\nbaz") end it 'parses variables with "." in the name' do expect(env("FOO.BAR=foobar")).to eql("FOO.BAR" => "foobar") end it "strips unquoted values" do expect(env("foo=bar ")).to eql("foo" => "bar") # not 'bar ' end it "ignores lines that are not variable assignments" do expect(env("lol$wut")).to eql({}) end it "ignores empty lines" do expect(env("\n \t \nfoo=bar\n \nfizz=buzz")) .to eql("foo" => "bar", "fizz" => "buzz") end it "ignores inline comments" do expect(env("foo=bar # this is foo")).to eql("foo" => "bar") end it "allows # in quoted value" do expect(env('foo="bar#baz" # comment')).to eql("foo" => "bar#baz") end it "ignores comment lines" do expect(env("\n\n\n # HERE GOES FOO \nfoo=bar")).to eql("foo" => "bar") end it "ignores commented out variables" do expect(env("# HELLO=world\n")).to eql({}) end it "ignores comment" do expect(env("# Uncomment to activate:\n")).to eql({}) end it "parses # in quoted values" do expect(env('foo="ba#r"')).to eql("foo" => "ba#r") expect(env("foo='ba#r'")).to eql("foo" => "ba#r") end it "parses # in quoted values with following spaces" do expect(env('foo="ba#r" ')).to eql("foo" => "ba#r") expect(env("foo='ba#r' ")).to eql("foo" => "ba#r") end it "parses empty values" do expect(env("foo=")).to eql("foo" => "") end if RUBY_VERSION > "1.8.7" it "parses shell commands interpolated in $()" do expect(env("echo=$(echo hello)")).to eql("echo" => "hello") end it "allows balanced parentheses within interpolated shell commands" do expect(env('echo=$(echo "$(echo "$(echo "$(echo hello)")")")')) .to eql("echo" => "hello") end it "doesn't interpolate shell commands when escape says not to" do expect(env('echo=escaped-\$(echo hello)')) .to eql("echo" => "escaped-$(echo hello)") end it "is not thrown off by quotes in interpolated shell commands" do expect(env('interp=$(echo "Quotes won\'t be a problem")')["interp"]) .to eql("Quotes won't be a problem") end it "supports carriage return" do expect(env("FOO=bar\rbaz=fbb")).to eql("FOO" => "bar", "baz" => "fbb") end it "supports carriage return combine with new line" do expect(env("FOO=bar\r\nbaz=fbb")).to eql("FOO" => "bar", "baz" => "fbb") end it "expands carriage return in quoted strings" do expect(env('FOO="bar\rbaz"')).to eql("FOO" => "bar\rbaz") end it "escape $ properly when no alphabets/numbers/_ are followed by it" do expect(env("FOO=\"bar\\$ \\$\\$\"")).to eql("FOO" => "bar$ $$") end # echo bar $ -> prints bar $ in the shell it "ignore $ when it is not escaped and no variable is followed by it" do expect(env("FOO=\"bar $ \"")).to eql("FOO" => "bar $ ") end # This functionality is not supported on JRuby or Rubinius if (!defined?(RUBY_ENGINE) || RUBY_ENGINE != "jruby") && !defined?(Rubinius) it "substitutes shell variables within interpolated shell commands" do expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))["interp"]) .to eql("VAR1 is var1") end end end end dotenv-2.4.0/spec/dotenv/rails_spec.rb000066400000000000000000000041571326752644000177360ustar00rootroot00000000000000require "spec_helper" require "rails" require "dotenv/rails" describe Dotenv::Railtie do # Fake watcher for Spring class SpecWatcher attr_reader :items def initialize @items = [] end def add(*items) @items |= items end end before do Rails.env = "test" allow(Rails).to receive(:root) .and_return Pathname.new(File.expand_path("../../fixtures", __FILE__)) Rails.application = double(:application) Spring.watcher = SpecWatcher.new end after do # Reset Spring.watcher = nil Rails.application = nil end context "before_configuration" do it "calls #load" do expect(Dotenv::Railtie.instance).to receive(:load) ActiveSupport.run_load_hooks(:before_configuration) end end context "load" do before { Dotenv::Railtie.load } it "watches .env with Spring" do expect(Spring.watcher.items).to include(Rails.root.join(".env").to_s) end it "watches other loaded files with Spring" do path = fixture_path("plain.env") Dotenv.load(path) expect(Spring.watcher.items).to include(path) end it "does not load .env.local in test rails environment" do expect(Dotenv::Railtie.instance.send(:dotenv_files)).to eql( [ Rails.root.join(".env.test.local"), Rails.root.join(".env.test"), Rails.root.join(".env") ] ) end it "does load .env.local in development environment" do Rails.env = "development" expect(Dotenv::Railtie.instance.send(:dotenv_files)).to eql( [ Rails.root.join(".env.development.local"), Rails.root.join(".env.local"), Rails.root.join(".env.development"), Rails.root.join(".env") ] ) end it "loads .env.test before .env" do expect(ENV["DOTENV"]).to eql("test") end context "when Rails.root is nil" do before do allow(Rails).to receive(:root).and_return(nil) end it "falls back to RAILS_ROOT" do ENV["RAILS_ROOT"] = "/tmp" expect(Dotenv::Railtie.root.to_s).to eql("/tmp") end end end end dotenv-2.4.0/spec/dotenv_spec.rb000066400000000000000000000107421326752644000166210ustar00rootroot00000000000000require "spec_helper" describe Dotenv do before do Dir.chdir(File.expand_path("../fixtures", __FILE__)) end shared_examples "load" do context "with no args" do let(:env_files) { [] } it "defaults to .env" do expect(Dotenv::Environment).to receive(:new).with(expand(".env"), anything) .and_return(double(apply: {}, apply!: {})) subject end end context "with a tilde path" do let(:env_files) { ["~/.env"] } it "expands the path" do expected = expand("~/.env") allow(File).to receive(:exist?) { |arg| arg == expected } expect(Dotenv::Environment).to receive(:new).with(expected, anything) .and_return(double(apply: {}, apply!: {})) subject end end context "with multiple files" do let(:env_files) { [".env", fixture_path("plain.env")] } let(:expected) do { "OPTION_A" => "1", "OPTION_B" => "2", "OPTION_C" => "3", "OPTION_D" => "4", "OPTION_E" => "5", "PLAIN" => "true", "DOTENV" => "true" } end it "loads all files" do subject expected.each do |key, value| expect(ENV[key]).to eq(value) end end it "returns hash of loaded environments" do expect(subject).to eq(expected) end end end describe "load" do let(:env_files) { [] } subject { Dotenv.load(*env_files) } it_behaves_like "load" it "initializes the Environment with a truthy is_load" do expect(Dotenv::Environment).to receive(:new).with(anything, true) .and_return(double(apply: {}, apply!: {})) subject end context "when the file does not exist" do let(:env_files) { [".env_does_not_exist"] } it "fails silently" do expect { subject }.not_to raise_error expect(ENV.keys).to eq(@env_keys) end end end describe "load!" do let(:env_files) { [] } subject { Dotenv.load!(*env_files) } it_behaves_like "load" it "initializes Environment with truthy is_load" do expect(Dotenv::Environment).to receive(:new).with(anything, true) .and_return(double(apply: {}, apply!: {})) subject end context "when one file exists and one does not" do let(:env_files) { [".env", ".env_does_not_exist"] } it "raises an Errno::ENOENT error" do expect { subject }.to raise_error(Errno::ENOENT) end end end describe "overload" do let(:env_files) { [fixture_path("plain.env")] } subject { Dotenv.overload(*env_files) } it_behaves_like "load" it "initializes the Environment with a falsey is_load" do expect(Dotenv::Environment).to receive(:new).with(anything, false) .and_return(double(apply: {}, apply!: {})) subject end context "when loading a file containing already set variables" do let(:env_files) { [fixture_path("plain.env")] } it "overrides any existing ENV variables" do ENV["OPTION_A"] = "predefined" subject expect(ENV["OPTION_A"]).to eq("1") end end context "when the file does not exist" do let(:env_files) { [".env_does_not_exist"] } it "fails silently" do expect { subject }.not_to raise_error expect(ENV.keys).to eq(@env_keys) end end end describe "with an instrumenter" do let(:instrumenter) { double("instrumenter", instrument: {}) } before { Dotenv.instrumenter = instrumenter } after { Dotenv.instrumenter = nil } describe "load" do it "instruments if the file exists" do expect(instrumenter).to receive(:instrument) do |name, payload| expect(name).to eq("dotenv.load") expect(payload[:env]).to be_instance_of(Dotenv::Environment) {} end Dotenv.load end it "does not instrument if file does not exist" do expect(instrumenter).to receive(:instrument).never Dotenv.load ".doesnotexist" end end end describe "Unicode" do subject { fixture_path("bom.env") } it "loads a file with a Unicode BOM" do expect(Dotenv.load(subject)).to eql("BOM" => "UTF-8") end it "fixture file has UTF-8 BOM" do contents = File.open(subject, "rb", &:read).force_encoding("UTF-8") expect(contents).to start_with("\xEF\xBB\xBF".force_encoding("UTF-8")) end end def expand(path) File.expand_path path end end dotenv-2.4.0/spec/fixtures/000077500000000000000000000000001326752644000156305ustar00rootroot00000000000000dotenv-2.4.0/spec/fixtures/.env000066400000000000000000000000141326752644000164140ustar00rootroot00000000000000DOTENV=true dotenv-2.4.0/spec/fixtures/.env.development000066400000000000000000000000531326752644000207400ustar00rootroot00000000000000FROM_RAILS_ENV=.env.development DOTENV=dev dotenv-2.4.0/spec/fixtures/.env.development.local000066400000000000000000000001021326752644000220240ustar00rootroot00000000000000FROM_RAILS_ENV=.env.test FROM_LOCAL=true DOTENV=development-local dotenv-2.4.0/spec/fixtures/.env.local000066400000000000000000000000351326752644000175100ustar00rootroot00000000000000FROM_LOCAL=true DOTENV=local dotenv-2.4.0/spec/fixtures/.env.test000066400000000000000000000000451326752644000173760ustar00rootroot00000000000000FROM_RAILS_ENV=.env.test DOTENV=test dotenv-2.4.0/spec/fixtures/bom.env000066400000000000000000000000141326752644000171120ustar00rootroot00000000000000BOM=UTF-8dotenv-2.4.0/spec/fixtures/exported.env000066400000000000000000000000471326752644000201750ustar00rootroot00000000000000export OPTION_A=2 export OPTION_B='\n' dotenv-2.4.0/spec/fixtures/plain.env000066400000000000000000000001061326752644000174420ustar00rootroot00000000000000PLAIN=true OPTION_A=1 OPTION_B=2 OPTION_C= 3 OPTION_D =4 OPTION_E = 5 dotenv-2.4.0/spec/fixtures/quoted.env000066400000000000000000000001641326752644000176440ustar00rootroot00000000000000QUOTED=true OPTION_A='1' OPTION_B='2' OPTION_C='' OPTION_D='\n' OPTION_E="1" OPTION_F="2" OPTION_G="" OPTION_H="\n" dotenv-2.4.0/spec/fixtures/yaml.env000066400000000000000000000000661326752644000173060ustar00rootroot00000000000000OPTION_A: 1 OPTION_B: '2' OPTION_C: '' OPTION_D: '\n' dotenv-2.4.0/spec/spec_helper.rb000066400000000000000000000004461326752644000166010ustar00rootroot00000000000000require "dotenv" RSpec.configure do |config| # Restore the state of ENV after each spec config.before { @env_keys = ENV.keys } config.after { ENV.delete_if { |k, _v| !@env_keys.include?(k) } } end def fixture_path(name) File.join(File.expand_path("../fixtures", __FILE__), name) end