From 1791280dd49a2f74b99a12feda5aa1169d4ec963 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Tue, 3 Sep 2013 21:56:30 -0400 Subject: [PATCH 01/33] Set license in gemspec Closes #56 --- dotenv.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/dotenv.gemspec b/dotenv.gemspec index 4c966c16..d78dffd0 100644 --- a/dotenv.gemspec +++ b/dotenv.gemspec @@ -8,6 +8,7 @@ Gem::Specification.new do |gem| gem.description = %q{Loads environment variables from `.env`.} gem.summary = %q{Loads environment variables from `.env`.} gem.homepage = "https://github.com/bkeepers/dotenv" + gem.license = 'MIT' gem.files = `git ls-files`.split($\) gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) } From 491e184611a3b82a16de40603245983c9cb5f160 Mon Sep 17 00:00:00 2001 From: Eduardo Gutierrez Date: Wed, 25 Sep 2013 15:39:45 -0400 Subject: [PATCH 02/33] Add `Dotenv::Environment#apply!` `#apply` will override any existing environment variables addressing dotenv#38 and dotenv#57. --- lib/dotenv/environment.rb | 4 ++++ spec/dotenv/environment_spec.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 4a1d146b..6fe59fc8 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -72,5 +72,9 @@ def read def apply each { |k,v| ENV[k] ||= v } end + + def apply! + each { |k,v| ENV[k] = v } + end end end diff --git a/spec/dotenv/environment_spec.rb b/spec/dotenv/environment_spec.rb index 7567ce72..50ba143f 100644 --- a/spec/dotenv/environment_spec.rb +++ b/spec/dotenv/environment_spec.rb @@ -29,6 +29,19 @@ 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 + it 'parses unquoted values' do expect(env('FOO=bar')).to eql('FOO' => 'bar') end From 4cafc36c0c36a0eb243a37d2e18d26be3dab3d43 Mon Sep 17 00:00:00 2001 From: Eduardo Gutierrez Date: Wed, 25 Sep 2013 16:33:59 -0400 Subject: [PATCH 03/33] Add `Dotenv.overload` Provides an interface to `Dotenv::Environment#apply`, overriding any environment variables if they are already set. --- lib/dotenv.rb | 8 ++++++++ spec/dotenv_spec.rb | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/dotenv.rb b/lib/dotenv.rb index 6f8c4968..2ffea317 100644 --- a/lib/dotenv.rb +++ b/lib/dotenv.rb @@ -8,6 +8,14 @@ def self.load(*filenames) end end + # same as `load`, but will override existing values in `ENV` + def self.overload(*filenames) + default_if_empty(filenames).inject({}) do |hash, filename| + filename = File.expand_path filename + hash.merge(File.exists?(filename) ? Environment.new(filename).apply! : {}) + end + end + # same as `load`, but raises Errno::ENOENT if any files don't exist def self.load!(*filenames) load( diff --git a/spec/dotenv_spec.rb b/spec/dotenv_spec.rb index a5cd3684..51ba555b 100644 --- a/spec/dotenv_spec.rb +++ b/spec/dotenv_spec.rb @@ -82,6 +82,17 @@ end end + describe 'overload' do + it 'overrides any existing ENV variables' do + ENV['OPTION_A'] = 'predefined' + path = fixture_path 'plain.env' + + Dotenv.overload(path) + + expect(ENV['OPTION_A']).to eq('1') + end + end + def fixture_path(name) File.join(File.expand_path('../fixtures', __FILE__), name) end From bea383bd504aabc934d0584c51645b4d83a53ee5 Mon Sep 17 00:00:00 2001 From: Samuel Garneau Date: Fri, 27 Sep 2013 09:12:25 -0400 Subject: [PATCH 04/33] Add dotenv_role config variable --- lib/dotenv/capistrano/recipes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/dotenv/capistrano/recipes.rb b/lib/dotenv/capistrano/recipes.rb index 32293048..a3ed1f6b 100644 --- a/lib/dotenv/capistrano/recipes.rb +++ b/lib/dotenv/capistrano/recipes.rb @@ -1,9 +1,10 @@ Capistrano::Configuration.instance(:must_exist).load do _cset(:dotenv_path){ "#{shared_path}/.env" } + _cset(:dotenv_role){ [:app] } namespace :dotenv do desc "Symlink shared .env to current release" - task :symlink, roles: :app do + task :symlink, roles: lambda { dotenv_role } do run "ln -nfs #{dotenv_path} #{release_path}/.env" end end From be12ccc52ae47c0cd104652c166602096000f922 Mon Sep 17 00:00:00 2001 From: Samuel Garneau Date: Wed, 2 Oct 2013 13:31:29 -0400 Subject: [PATCH 05/33] Execute dotenv:symlink for all roles --- lib/dotenv/capistrano/recipes.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/dotenv/capistrano/recipes.rb b/lib/dotenv/capistrano/recipes.rb index a3ed1f6b..ea2db0ee 100644 --- a/lib/dotenv/capistrano/recipes.rb +++ b/lib/dotenv/capistrano/recipes.rb @@ -1,10 +1,11 @@ Capistrano::Configuration.instance(:must_exist).load do _cset(:dotenv_path){ "#{shared_path}/.env" } - _cset(:dotenv_role){ [:app] } + + symlink_args = (role = fetch(:dotenv_role, nil) ? {roles: role} : {}) namespace :dotenv do desc "Symlink shared .env to current release" - task :symlink, roles: lambda { dotenv_role } do + task :symlink, symlink_args do run "ln -nfs #{dotenv_path} #{release_path}/.env" end end From c51de496dbc60f4c1b854b87c71aafbe1da01c8b Mon Sep 17 00:00:00 2001 From: Javier Date: Thu, 17 Oct 2013 12:37:31 +0200 Subject: [PATCH 06/33] Updated Readme to include comment about using dotenv in production with capistrano --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6fe36c34..e38e110e 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,13 @@ In your `config/deploy.rb` file: require "dotenv/capistrano" ``` -It will symlink the `.env` located in `/path/to/shared` in the new release. +It will symlink the `.env` located in `/path/to/shared` in the new release. + +Remember to add :production group to the dotenv-rails gem in your application's Gemfile: + +```ruby +gem 'dotenv-rails', :groups => [:development, :test, :production] +``` ## Should I commit my .env file? From 4f9fb060002b901eb6207de6270feb58f179b9ff Mon Sep 17 00:00:00 2001 From: Nikita Fedyashev Date: Sun, 20 Oct 2013 17:17:19 +0300 Subject: [PATCH 07/33] Add Capistano3+ versions compatibility --- README.md | 14 ++++++++++++++ lib/dotenv/capistrano.rb | 12 +++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6fe36c34..c7c00e62 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,8 @@ config.fog_directory = ENV['S3_BUCKET'] ## Capistrano integration +If you use `2.x.x` version: + In your `config/deploy.rb` file: ```ruby @@ -82,6 +84,18 @@ require "dotenv/capistrano" It will symlink the `.env` located in `/path/to/shared` in the new release. +--- + +If you use `3.x.x` version: + +In your `config/deploy.rb` file: + +add .env to the list of linked files, similar to: + +```ruby +set :linked_files, %w{config/database.yml .env} +``` + ## Should I commit my .env file? It is recommended that you store development-only settings in your `.env` file, and commit it to your repository. Make sure that all your credentials for your development environment are different from your other deployments. This makes it easy for other developers to get started on your project, without compromising your credentials for other environments. diff --git a/lib/dotenv/capistrano.rb b/lib/dotenv/capistrano.rb index dc6dd02d..bc8188e6 100644 --- a/lib/dotenv/capistrano.rb +++ b/lib/dotenv/capistrano.rb @@ -1,5 +1,11 @@ -require 'dotenv/capistrano/recipes' +require 'capistrano/version' -Capistrano::Configuration.instance(:must_exist).load do - before "deploy:finalize_update", "dotenv:symlink" +if defined?(Capistrano::VERSION) && Capistrano::VERSION => '3.0' + raise 'Please read https://github.com/bkeepers/dotenv#capistrano-integration to update your dotenv configuration for new Capistrano version' +else + require 'dotenv/capistrano/recipes' + + Capistrano::Configuration.instance(:must_exist).load do + before "deploy:finalize_update", "dotenv:symlink" + end end From 1595b33a448f19116a8b4bc2df97b8ce1cace6c6 Mon Sep 17 00:00:00 2001 From: Jonathan Camenisch Date: Fri, 1 Nov 2013 19:23:55 -0500 Subject: [PATCH 08/33] Enable execution of interpolated shell commands at least for ruby >= 1.9 --- lib/dotenv/environment.rb | 20 ++++++++++++++++++++ spec/dotenv/environment_spec.rb | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 4a1d146b..9e5d1dc2 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -26,6 +26,15 @@ class Environment < Hash \}? # closing brace ) /xi + INTERPOLATED_SHELL_COMMAND = / + (?\\)? + \$ + (? # 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 initialize(filename) @filename = filename @@ -58,6 +67,17 @@ def load value = value.sub(parts[0...-1].join(''), replace || '') end + # Process interpolated shell commands + value.gsub!(INTERPOLATED_SHELL_COMMAND) do |*| + command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses + + if $~[:backslash] + $~[0][1..-1] + else + `#{command}`.chomp + end + end + self[key] = value elsif line !~ /\A\s*(?:#.*)?\z/ # not comment or blank line raise FormatError, "Line #{line.inspect} doesn't match format" diff --git a/spec/dotenv/environment_spec.rb b/spec/dotenv/environment_spec.rb index 7567ce72..c420ae1c 100644 --- a/spec/dotenv/environment_spec.rb +++ b/spec/dotenv/environment_spec.rb @@ -125,6 +125,26 @@ expect(env("foo='ba#r'")).to eql('foo' => 'ba#r') end + it 'parses shell commands interpolated in $()' do + expect(env('ruby_v=$(ruby -v)')).to eql('ruby_v' => RUBY_DESCRIPTION) + end + + it 'allows balanced parentheses within interpolated shell commands' do + expect(env('ruby_v=$(echo "$(echo "$(echo "$(ruby -v)")")")')).to eql('ruby_v' => RUBY_DESCRIPTION) + end + + it "doesn't interpolate shell commands when escape says not to" do + expect(env('ruby_v=escaped-\$(ruby -v)')).to eql('ruby_v' => 'escaped-$(ruby -v)') + 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 'substitutes shell variables within interpolated shell commands' do + expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))['interp']).to eql("VAR1 is var1") + end + require 'tempfile' def env(text) file = Tempfile.new('dotenv') From 837021444301b355f6be9878436adcb370539ca1 Mon Sep 17 00:00:00 2001 From: Jonathan Camenisch Date: Fri, 1 Nov 2013 21:40:18 -0500 Subject: [PATCH 09/33] Disable interpolated shell commands for Ruby <= 1.8.7 --- lib/dotenv/environment.rb | 16 +++++++++------- spec/dotenv/environment_spec.rb | 30 ++++++++++++++++-------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 9e5d1dc2..138076d8 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -67,14 +67,16 @@ def load value = value.sub(parts[0...-1].join(''), replace || '') end - # Process interpolated shell commands - value.gsub!(INTERPOLATED_SHELL_COMMAND) do |*| - command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses + if RUBY_VERSION > '1.8.7' + # Process interpolated shell commands + value.gsub!(INTERPOLATED_SHELL_COMMAND) do |*| + command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses - if $~[:backslash] - $~[0][1..-1] - else - `#{command}`.chomp + if $~[:backslash] + $~[0][1..-1] + else + `#{command}`.chomp + end end end diff --git a/spec/dotenv/environment_spec.rb b/spec/dotenv/environment_spec.rb index c420ae1c..a5ae7ad2 100644 --- a/spec/dotenv/environment_spec.rb +++ b/spec/dotenv/environment_spec.rb @@ -125,24 +125,26 @@ expect(env("foo='ba#r'")).to eql('foo' => 'ba#r') end - it 'parses shell commands interpolated in $()' do - expect(env('ruby_v=$(ruby -v)')).to eql('ruby_v' => RUBY_DESCRIPTION) - end + if RUBY_VERSION > '1.8.7' + it 'parses shell commands interpolated in $()' do + expect(env('ruby_v=$(ruby -v)')).to eql('ruby_v' => RUBY_DESCRIPTION) + end - it 'allows balanced parentheses within interpolated shell commands' do - expect(env('ruby_v=$(echo "$(echo "$(echo "$(ruby -v)")")")')).to eql('ruby_v' => RUBY_DESCRIPTION) - end + it 'allows balanced parentheses within interpolated shell commands' do + expect(env('ruby_v=$(echo "$(echo "$(echo "$(ruby -v)")")")')).to eql('ruby_v' => RUBY_DESCRIPTION) + end - it "doesn't interpolate shell commands when escape says not to" do - expect(env('ruby_v=escaped-\$(ruby -v)')).to eql('ruby_v' => 'escaped-$(ruby -v)') - end + it "doesn't interpolate shell commands when escape says not to" do + expect(env('ruby_v=escaped-\$(ruby -v)')).to eql('ruby_v' => 'escaped-$(ruby -v)') + 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 '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 'substitutes shell variables within interpolated shell commands' do - expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))['interp']).to eql("VAR1 is var1") + 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 require 'tempfile' From 344490bb34c81870c34bc5f165c6210fffc9ad81 Mon Sep 17 00:00:00 2001 From: Daniel Leavitt Date: Sun, 3 Nov 2013 14:24:23 -0800 Subject: [PATCH 10/33] Fix syntax error in capistrano.rb --- lib/dotenv/capistrano.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dotenv/capistrano.rb b/lib/dotenv/capistrano.rb index bc8188e6..0f49b7e8 100644 --- a/lib/dotenv/capistrano.rb +++ b/lib/dotenv/capistrano.rb @@ -1,6 +1,6 @@ require 'capistrano/version' -if defined?(Capistrano::VERSION) && Capistrano::VERSION => '3.0' +if defined?(Capistrano::VERSION) && Capistrano::VERSION >= '3.0' raise 'Please read https://github.com/bkeepers/dotenv#capistrano-integration to update your dotenv configuration for new Capistrano version' else require 'dotenv/capistrano/recipes' From e156b69b4246da8e9c51f336c0e371a81b6c5c34 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 11 Nov 2013 12:39:57 -0500 Subject: [PATCH 11/33] try to fix specs on ruby 1.8.7/ree --- .travis.yml | 1 + Gemfile | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa0836e9..a224e206 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,4 @@ rvm: - 1.9.3 - 1.8.7 - ree +bundler_args: --without=guard diff --git a/Gemfile b/Gemfile index 79de2356..573648fd 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,8 @@ source 'https://rubygems.org' gemspec :name => 'dotenv' -gem 'guard-rspec' -gem 'guard-bundler' -gem 'rb-fsevent' +group :guard do + gem 'guard-rspec' + gem 'guard-bundler' + gem 'rb-fsevent' +end From 0d7f1c3324a24e8569957a125f7a53b81caddebb Mon Sep 17 00:00:00 2001 From: Marcos Wright-Kuhns Date: Sat, 23 Nov 2013 11:07:07 -0800 Subject: [PATCH 12/33] Split unsupported Regexp into an optional module At this point tests are passing in Ruby 1.8.7! --- lib/dotenv/environment.rb | 30 ++++++++++-------------------- lib/dotenv/environment_modern.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 lib/dotenv/environment_modern.rb diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 138076d8..b2bdcd79 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -1,5 +1,9 @@ require 'dotenv/format_error' +if RUBY_VERSION > '1.8.7' + require 'dotenv/environment_modern' +end + module Dotenv class Environment < Hash LINE = / @@ -26,15 +30,10 @@ class Environment < Hash \}? # closing brace ) /xi - INTERPOLATED_SHELL_COMMAND = / - (?\\)? - \$ - (? # 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 + + if RUBY_VERSION > '1.8.7' + include ::Dotenv::EnvironmentModern + end def initialize(filename) @filename = filename @@ -67,17 +66,8 @@ def load value = value.sub(parts[0...-1].join(''), replace || '') end - if RUBY_VERSION > '1.8.7' - # Process interpolated shell commands - value.gsub!(INTERPOLATED_SHELL_COMMAND) do |*| - command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses - - if $~[:backslash] - $~[0][1..-1] - else - `#{command}`.chomp - end - end + if respond_to?(:process_interpolated_shell_commands) + value = process_interpolated_shell_commands(value) end self[key] = value diff --git a/lib/dotenv/environment_modern.rb b/lib/dotenv/environment_modern.rb new file mode 100644 index 00000000..3341ccd2 --- /dev/null +++ b/lib/dotenv/environment_modern.rb @@ -0,0 +1,26 @@ +module Dotenv + module EnvironmentModern + INTERPOLATED_SHELL_COMMAND = / + (?\\)? + \$ + (? # 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 process_interpolated_shell_commands(value) + # Process interpolated shell commands + value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| + command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses + + if $~[:backslash] + $~[0][1..-1] + else + `#{command}`.chomp + end + end + end + end +end \ No newline at end of file From 9aa522c1fdecbec92c4af307ae0fcc84f4495fda Mon Sep 17 00:00:00 2001 From: Marcos Wright-Kuhns Date: Sat, 23 Nov 2013 11:24:47 -0800 Subject: [PATCH 13/33] One step towards multiple supporting multiple extensions --- lib/dotenv/environment.rb | 9 ++++-- .../interpolated_shell_commands.rb | 32 +++++++++++++++++++ lib/dotenv/environment_modern.rb | 26 --------------- 3 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 lib/dotenv/environment_extensions/interpolated_shell_commands.rb delete mode 100644 lib/dotenv/environment_modern.rb diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index b2bdcd79..15e1a198 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -1,7 +1,7 @@ require 'dotenv/format_error' if RUBY_VERSION > '1.8.7' - require 'dotenv/environment_modern' + require 'dotenv/environment_extensions/interpolated_shell_commands' end module Dotenv @@ -31,8 +31,11 @@ class Environment < Hash ) /xi - if RUBY_VERSION > '1.8.7' - include ::Dotenv::EnvironmentModern + if defined?(::Dotenv::EnvironmentExtensions) + ::Dotenv::EnvironmentExtensions.constants.each do |extension| + extension = ::Dotenv::EnvironmentExtensions.const_get(extension) + include extension if extension.is_a?(Module) + end end def initialize(filename) diff --git a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb b/lib/dotenv/environment_extensions/interpolated_shell_commands.rb new file mode 100644 index 00000000..87e52075 --- /dev/null +++ b/lib/dotenv/environment_extensions/interpolated_shell_commands.rb @@ -0,0 +1,32 @@ +module Dotenv + module EnvironmentExtensions + + module IterpolatedShellCommands + + INTERPOLATED_SHELL_COMMAND = / + (?\\)? + \$ + (? # 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 process_interpolated_shell_commands(value) + # Process interpolated shell commands + value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| + command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses + + if $~[:backslash] + $~[0][1..-1] + else + `#{command}`.chomp + end + end + end + + end + + end +end \ No newline at end of file diff --git a/lib/dotenv/environment_modern.rb b/lib/dotenv/environment_modern.rb deleted file mode 100644 index 3341ccd2..00000000 --- a/lib/dotenv/environment_modern.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Dotenv - module EnvironmentModern - INTERPOLATED_SHELL_COMMAND = / - (?\\)? - \$ - (? # 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 process_interpolated_shell_commands(value) - # Process interpolated shell commands - value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| - command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses - - if $~[:backslash] - $~[0][1..-1] - else - `#{command}`.chomp - end - end - end - end -end \ No newline at end of file From ee76f125c1defd3ca1544bf3074c2aeaf262db6c Mon Sep 17 00:00:00 2001 From: Marcos Wright-Kuhns Date: Sat, 23 Nov 2013 11:37:47 -0800 Subject: [PATCH 14/33] Allow for more Environment#load extensions in the future --- lib/dotenv/environment.rb | 14 +++++- .../interpolated_shell_commands.rb | 45 +++++++++++-------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 15e1a198..41fd2699 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -6,6 +6,8 @@ module Dotenv class Environment < Hash + @load_extensions = [] + LINE = / \A (?:export\s+)? # optional export @@ -31,6 +33,14 @@ class Environment < Hash ) /xi + def self.load_extensions + @load_extensions + end + + def self.register_load_extension(proc) + @load_extensions += [proc] + end + if defined?(::Dotenv::EnvironmentExtensions) ::Dotenv::EnvironmentExtensions.constants.each do |extension| extension = ::Dotenv::EnvironmentExtensions.const_get(extension) @@ -69,8 +79,8 @@ def load value = value.sub(parts[0...-1].join(''), replace || '') end - if respond_to?(:process_interpolated_shell_commands) - value = process_interpolated_shell_commands(value) + self.class.load_extensions.each do |extension_proc| + value = extension_proc.call(value) end self[key] = value diff --git a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb b/lib/dotenv/environment_extensions/interpolated_shell_commands.rb index 87e52075..96410962 100644 --- a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb +++ b/lib/dotenv/environment_extensions/interpolated_shell_commands.rb @@ -3,25 +3,32 @@ module EnvironmentExtensions module IterpolatedShellCommands - INTERPOLATED_SHELL_COMMAND = / - (?\\)? - \$ - (? # 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 process_interpolated_shell_commands(value) - # Process interpolated shell commands - value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| - command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses - - if $~[:backslash] - $~[0][1..-1] - else - `#{command}`.chomp + class << self + + INTERPOLATED_SHELL_COMMAND = / + (?\\)? + \$ + (? # 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 included(base) + base.register_load_extension(method(:process_interpolated_shell_commands)) + end + + def process_interpolated_shell_commands(value) + # Process interpolated shell commands + value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| + command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses + + if $~[:backslash] + $~[0][1..-1] + else + `#{command}`.chomp + end end end end From b6d9d92f6ebeb1011f16f103ceac04222b2c03fe Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 11 Nov 2013 13:09:48 -0500 Subject: [PATCH 15/33] update changelog --- Changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Changelog.md b/Changelog.md index b2ff05e9..2eccd414 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,15 @@ # Changelog +## 0.10.0 - unreleased + +* Add support for executing interpolated commands. + + HEAD_SHA=$(git rev-parse HEAD) + +* Add `dotenv_role` option in Capistrano. + + set :dotenv_role, [:app web] + ## 0.9.0 - Aug 29, 2013 * Add support for variable expansion. From bb3d631969fb90950ad4502502fbc24d24660884 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 2 Dec 2013 16:45:24 -0500 Subject: [PATCH 16/33] Move variable loading to an extension --- lib/dotenv/environment.rb | 23 +---------- .../interpolated_shell_commands.rb | 5 +-- lib/dotenv/environment_extensions/variable.rb | 41 +++++++++++++++++++ 3 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 lib/dotenv/environment_extensions/variable.rb diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 41fd2699..7461dcc6 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -3,6 +3,7 @@ if RUBY_VERSION > '1.8.7' require 'dotenv/environment_extensions/interpolated_shell_commands' end +require 'dotenv/environment_extensions/variable' module Dotenv class Environment < Hash @@ -23,15 +24,6 @@ class Environment < Hash (?:\s*\#.*)? # optional comment \z /x - VARIABLE = / - (\\)? - (\$) - ( # collect braces with var for sub - \{? # allow brace wrapping - ([A-Z0-9_]+) # match the variable - \}? # closing brace - ) - /xi def self.load_extensions @load_extensions @@ -68,19 +60,8 @@ def load value = value.gsub(/\\([^$])/, '\1') end - # Process embedded variables - value.scan(VARIABLE).each do |parts| - if parts.first == '\\' - replace = parts[1...-1].join('') - else - replace = self.fetch(parts.last) { ENV[parts.last] } - end - - value = value.sub(parts[0...-1].join(''), replace || '') - end - self.class.load_extensions.each do |extension_proc| - value = extension_proc.call(value) + value = extension_proc.call(value, self) end self[key] = value diff --git a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb b/lib/dotenv/environment_extensions/interpolated_shell_commands.rb index 96410962..fab3094b 100644 --- a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb +++ b/lib/dotenv/environment_extensions/interpolated_shell_commands.rb @@ -19,7 +19,7 @@ def included(base) base.register_load_extension(method(:process_interpolated_shell_commands)) end - def process_interpolated_shell_commands(value) + def process_interpolated_shell_commands(value, env) # Process interpolated shell commands value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses @@ -34,6 +34,5 @@ def process_interpolated_shell_commands(value) end end - end -end \ No newline at end of file +end diff --git a/lib/dotenv/environment_extensions/variable.rb b/lib/dotenv/environment_extensions/variable.rb new file mode 100644 index 00000000..ee04731c --- /dev/null +++ b/lib/dotenv/environment_extensions/variable.rb @@ -0,0 +1,41 @@ +module Dotenv + module EnvironmentExtensions + + module Variable + + class << self + + VARIABLE = / + (\\)? + (\$) + ( # collect braces with var for sub + \{? # allow brace wrapping + ([A-Z0-9_]+) # match the variable + \}? # closing brace + ) + /xi + + def included(base) + base.register_load_extension(method(:process_variables)) + end + + def process_variables(value, env) + # Process embedded variables + value.scan(VARIABLE).each do |parts| + if parts.first == '\\' + replace = parts[1...-1].join('') + else + replace = env.fetch(parts.last) { ENV[parts.last] } + end + + value = value.sub(parts[0...-1].join(''), replace || '') + end + + value + end + end + + end + + end +end From ecf797f3acd398d45fbf8b3ffa164c5e8a41a744 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Mon, 2 Dec 2013 17:13:47 -0500 Subject: [PATCH 17/33] Clean up extensions, avoid explosing an extension API for now MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I think it would be really interesting eventually to expose this to other gems, but I’d like to experiment with it internally first. --- lib/dotenv/environment.rb | 26 ++++--------------- .../command.rb} | 12 +++------ .../variable.rb | 10 ++----- 3 files changed, 10 insertions(+), 38 deletions(-) rename lib/dotenv/{environment_extensions/interpolated_shell_commands.rb => substitutions/command.rb} (76%) rename lib/dotenv/{environment_extensions => substitutions}/variable.rb (80%) diff --git a/lib/dotenv/environment.rb b/lib/dotenv/environment.rb index 7461dcc6..316cde93 100644 --- a/lib/dotenv/environment.rb +++ b/lib/dotenv/environment.rb @@ -1,13 +1,12 @@ require 'dotenv/format_error' - +require 'dotenv/substitutions/variable' if RUBY_VERSION > '1.8.7' - require 'dotenv/environment_extensions/interpolated_shell_commands' + require 'dotenv/substitutions/command' end -require 'dotenv/environment_extensions/variable' module Dotenv class Environment < Hash - @load_extensions = [] + @@substitutions = Substitutions.constants.map { |const| Substitutions.const_get(const) } LINE = / \A @@ -25,21 +24,6 @@ class Environment < Hash \z /x - def self.load_extensions - @load_extensions - end - - def self.register_load_extension(proc) - @load_extensions += [proc] - end - - if defined?(::Dotenv::EnvironmentExtensions) - ::Dotenv::EnvironmentExtensions.constants.each do |extension| - extension = ::Dotenv::EnvironmentExtensions.const_get(extension) - include extension if extension.is_a?(Module) - end - end - def initialize(filename) @filename = filename load @@ -60,8 +44,8 @@ def load value = value.gsub(/\\([^$])/, '\1') end - self.class.load_extensions.each do |extension_proc| - value = extension_proc.call(value, self) + @@substitutions.each do |proc| + value = proc.call(value, self) end self[key] = value diff --git a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb b/lib/dotenv/substitutions/command.rb similarity index 76% rename from lib/dotenv/environment_extensions/interpolated_shell_commands.rb rename to lib/dotenv/substitutions/command.rb index fab3094b..75f6fcb1 100644 --- a/lib/dotenv/environment_extensions/interpolated_shell_commands.rb +++ b/lib/dotenv/substitutions/command.rb @@ -1,8 +1,6 @@ module Dotenv - module EnvironmentExtensions - - module IterpolatedShellCommands - + module Substitutions + module Command class << self INTERPOLATED_SHELL_COMMAND = / @@ -15,11 +13,7 @@ class << self ) /x - def included(base) - base.register_load_extension(method(:process_interpolated_shell_commands)) - end - - def process_interpolated_shell_commands(value, env) + def call(value, env) # Process interpolated shell commands value.gsub(INTERPOLATED_SHELL_COMMAND) do |*| command = $~[:cmd][1..-2] # Eliminate opening and closing parentheses diff --git a/lib/dotenv/environment_extensions/variable.rb b/lib/dotenv/substitutions/variable.rb similarity index 80% rename from lib/dotenv/environment_extensions/variable.rb rename to lib/dotenv/substitutions/variable.rb index ee04731c..f73aced5 100644 --- a/lib/dotenv/environment_extensions/variable.rb +++ b/lib/dotenv/substitutions/variable.rb @@ -1,8 +1,6 @@ module Dotenv - module EnvironmentExtensions - + module Substitutions module Variable - class << self VARIABLE = / @@ -15,11 +13,7 @@ class << self ) /xi - def included(base) - base.register_load_extension(method(:process_variables)) - end - - def process_variables(value, env) + def call(value, env) # Process embedded variables value.scan(VARIABLE).each do |parts| if parts.first == '\\' From 4f138f5e0bde978245d5ff50788254dfbcd9801d Mon Sep 17 00:00:00 2001 From: Kris Leech Date: Thu, 5 Dec 2013 11:52:38 +0000 Subject: [PATCH 18/33] Restrict build status to master branch Currently the build status badge is shown as failing because of failing tests in a branch. This restricts the build status badge to the master branch only. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d7832ca..f393e0c0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png)](https://travis-ci.org/bkeepers/dotenv) +# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.png?branch=master)](https://travis-ci.org/bkeepers/dotenv) Dotenv loads environment variables from `.env` into `ENV`. From b0206cfd1ba3d3216ea4098a3b975a12bebb5a16 Mon Sep 17 00:00:00 2001 From: RKushnir Date: Thu, 12 Dec 2013 19:02:24 +0200 Subject: [PATCH 19/33] Add a Readme note about adding the gem to the top of Gemfile [ci skip] Other gems may use `ENV` vars for initializing their settings. To ensure they use the correct values, `dotenv-rails` should appear at the top of the Gemfile to be loaded first. --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f393e0c0..ed75810b 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ But it is not always practical to set environment variables on development machi ### Rails -Add this line to your application's Gemfile: +Add this line to the top of your application's Gemfile: ```ruby gem 'dotenv-rails', :groups => [:development, :test] @@ -20,6 +20,8 @@ And then execute: $ bundle +It should be listed in the Gemfile before any other gems that use environment variables, otherwise those gems will get initialized with the wrong values. + ### Sinatra or Plain ol' Ruby Install the gem: From 05791dc8399e258b3fb282fa8e415b497fca924e Mon Sep 17 00:00:00 2001 From: Pietro Di Bello Date: Wed, 8 Jan 2014 23:33:20 +0100 Subject: [PATCH 20/33] Improving Capistrano integration docs I try to give more highlight to the need of adding the gem to the :production group in the Gemfile --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index ed75810b..91594190 100644 --- a/README.md +++ b/README.md @@ -76,25 +76,24 @@ config.fog_directory = ENV['S3_BUCKET'] ## Capistrano integration -If you use `2.x.x` version: - -In your `config/deploy.rb` file: +First, you should add the :production group to the dotenv-rails gem in your application's Gemfile: ```ruby -require "dotenv/capistrano" +gem 'dotenv-rails', :groups => [:development, :test, :production] ``` -It will symlink the `.env` located in `/path/to/shared` in the new release. +### Capistrano version 2.x.x -Remember to add :production group to the dotenv-rails gem in your application's Gemfile: +In your `config/deploy.rb` file: ```ruby -gem 'dotenv-rails', :groups => [:development, :test, :production] +require "dotenv/capistrano" ``` ---- +It will symlink the `.env` located in `/path/to/shared` in the new release. + -If you use `3.x.x` version: +### Capistrano version 3.x.x In your `config/deploy.rb` file: From 2a06b4ee149010e3d73570acf7294e74f39c5d02 Mon Sep 17 00:00:00 2001 From: "Peter M. Goldstein" Date: Fri, 27 Dec 2013 12:09:03 -0800 Subject: [PATCH 21/33] Add Ruby 2.1.0, Rubinius, JRuby to Travis config. Update deprecated syntax in specs to match the remainder. Add Rubinius gems to Gemfile. --- .travis.yml | 5 ++++- Gemfile | 4 ++++ spec/dotenv/environment_spec.rb | 7 +++++-- spec/dotenv_spec.rb | 6 +++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index a224e206..827df5f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,10 @@ language: ruby rvm: + - 2.1.0 - 2.0.0 - 1.9.3 - 1.8.7 - ree -bundler_args: --without=guard + - jruby-19mode + - rbx +bundler_args: --without=guard \ No newline at end of file diff --git a/Gemfile b/Gemfile index 573648fd..8a52d582 100644 --- a/Gemfile +++ b/Gemfile @@ -6,3 +6,7 @@ group :guard do gem 'guard-bundler' gem 'rb-fsevent' end + +platforms :rbx do + gem 'rubysl', '~> 2.0' # if using anything in the ruby standard library +end \ No newline at end of file diff --git a/spec/dotenv/environment_spec.rb b/spec/dotenv/environment_spec.rb index a5ae7ad2..9d6bd1bc 100644 --- a/spec/dotenv/environment_spec.rb +++ b/spec/dotenv/environment_spec.rb @@ -142,8 +142,11 @@ expect(env('interp=$(echo "Quotes won\'t be a problem")')['interp']).to eql("Quotes won't be a problem") end - it 'substitutes shell variables within interpolated shell commands' do - expect(env(%(VAR1=var1\ninterp=$(echo "VAR1 is $VAR1")))['interp']).to eql("VAR1 is var1") + # 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 diff --git a/spec/dotenv_spec.rb b/spec/dotenv_spec.rb index a5cd3684..885c8455 100644 --- a/spec/dotenv_spec.rb +++ b/spec/dotenv_spec.rb @@ -6,7 +6,7 @@ let(:env_files) { [] } it 'defaults to .env' do - Dotenv::Environment.should_receive(:new).with(expand('.env')). + expect(Dotenv::Environment).to receive(:new).with(expand('.env')). and_return(double(:apply => {})) subject end @@ -17,8 +17,8 @@ it 'expands the path' do expected = expand("~/.env") - File.stub(:exists?){ |arg| arg == expected } - Dotenv::Environment.should_receive(:new).with(expected). + allow(File).to receive(:exists?){ |arg| arg == expected } + expect(Dotenv::Environment).to receive(:new).with(expected). and_return(double(:apply => {})) subject end From ee49ca96bb65ffe888ef09288334fb0581692ebc Mon Sep 17 00:00:00 2001 From: Pietro Di Bello Date: Mon, 13 Jan 2014 22:03:55 +0100 Subject: [PATCH 22/33] Making a simpler note on Capistrano integration --- README.md | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 91594190..b9e95d3d 100644 --- a/README.md +++ b/README.md @@ -76,15 +76,11 @@ config.fog_directory = ENV['S3_BUCKET'] ## Capistrano integration -First, you should add the :production group to the dotenv-rails gem in your application's Gemfile: - -```ruby -gem 'dotenv-rails', :groups => [:development, :test, :production] -``` +If you want to use Dotenv with Capistrano in your production environment, make sure the dotenv gem is included in your Gemfile `:production` group. ### Capistrano version 2.x.x -In your `config/deploy.rb` file: +Add the gem to your `config/deploy.rb` file: ```ruby require "dotenv/capistrano" @@ -95,9 +91,7 @@ It will symlink the `.env` located in `/path/to/shared` in the new release. ### Capistrano version 3.x.x -In your `config/deploy.rb` file: - -add .env to the list of linked files, similar to: +Just add `.env` to the list of linked files, for example: ```ruby set :linked_files, %w{config/database.yml .env} From 32886c1ff77174fe0fba68b3474b7c5bfb92a6f6 Mon Sep 17 00:00:00 2001 From: Cyril Mougel Date: Tue, 4 Feb 2014 18:06:10 +0100 Subject: [PATCH 23/33] Ruby 1.8 compatibility All dotenv is Ruby 1.8 compatible but not the capistrano recipes. --- lib/dotenv/capistrano/recipes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dotenv/capistrano/recipes.rb b/lib/dotenv/capistrano/recipes.rb index ea2db0ee..1e1b226d 100644 --- a/lib/dotenv/capistrano/recipes.rb +++ b/lib/dotenv/capistrano/recipes.rb @@ -1,7 +1,7 @@ Capistrano::Configuration.instance(:must_exist).load do _cset(:dotenv_path){ "#{shared_path}/.env" } - symlink_args = (role = fetch(:dotenv_role, nil) ? {roles: role} : {}) + symlink_args = (role = fetch(:dotenv_role, nil) ? {:roles => role} : {}) namespace :dotenv do desc "Symlink shared .env to current release" From 103a4c96b325fd6ace320a8471434243302e88a6 Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Thu, 6 Feb 2014 08:37:28 +0200 Subject: [PATCH 24/33] Fix typo in specifications --- spec/dotenv/environment_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/dotenv/environment_spec.rb b/spec/dotenv/environment_spec.rb index 991f4b62..e74996d7 100644 --- a/spec/dotenv/environment_spec.rb +++ b/spec/dotenv/environment_spec.rb @@ -105,7 +105,7 @@ expect(env('FOO="bar\nbaz"')).to eql('FOO' => "bar\nbaz") end - it 'parses varibales with "." in the name' do + it 'parses variables with "." in the name' do expect(env('FOO.BAR=foobar')).to eql('FOO.BAR' => 'foobar') end From e2153d84f5b78a9658fae8b71fd92994e5cad26c Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Thu, 6 Feb 2014 09:07:05 +0200 Subject: [PATCH 25/33] Mark up 'ENV' consistently in documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b9e95d3d..ae064082 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Dotenv loads environment variables from `.env` into `ENV`. Storing [configuration in the environment](http://www.12factor.net/config) is one of the tenets of a [twelve-factor app](http://www.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 load variables from a `.env` file into ENV when the environment is bootstrapped. +But it is not always practical to set environment variables on development machines or continuous integration servers where multiple projects are run. Dotenv load variables from a `.env` file into `ENV` when the environment is bootstrapped. ## Installation From 26791124c4f1e9dae793bfe85754905cd52e8bcc Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Thu, 6 Feb 2014 20:38:10 +0200 Subject: [PATCH 26/33] Use code blocks consistently in documentation The documentation mixes both traditional code block syntax and fenced code block syntax. Stick to the latter for consistency. --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ae064082..f9d256d7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ gem 'dotenv-rails', :groups => [:development, :test] And then execute: - $ bundle +```shell +$ bundle +``` It should be listed in the Gemfile before any other gems that use environment variables, otherwise those gems will get initialized with the wrong values. @@ -26,7 +28,9 @@ It should be listed in the Gemfile before any other gems that use environment va Install the gem: - $ gem install dotenv +```shell +$ gem install dotenv +``` As early as possible in your application bootstrap process, load `.env`: From 540ffd7794cfaf04a0f6087ba1ab14f67ff60b81 Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Thu, 6 Feb 2014 20:38:35 +0200 Subject: [PATCH 27/33] Mention 'dotenv' executable in documentation The 'dotenv' executable is easy to miss yet useful in many situations. Mention it in the documentation. Following the example set by the changelog, refer to a Python script in the documentation to underline the point that using Dotenv this way is not specific to Ruby. --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index f9d256d7..faa859eb 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ require 'dotenv' Dotenv.load ``` +Alternatively, you can use the `dotenv` executable to launch your application: + +```shell +$ dotenv ./script.py +``` + To ensure `.env` is loaded in rake, load the tasks: ```ruby From 866d8e011a6c075198aa909dc12241b08a421300 Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Fri, 7 Feb 2014 11:03:56 +0200 Subject: [PATCH 28/33] Use single quotes consistently on require argument --- bin/dotenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dotenv b/bin/dotenv index 5c37b26a..fcaf9a74 100755 --- a/bin/dotenv +++ b/bin/dotenv @@ -1,6 +1,6 @@ #!/usr/bin/env ruby -require "dotenv" +require 'dotenv' begin Dotenv.load! From e00e6feeb33726c7057a974dca723398ff4de313 Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Fri, 7 Feb 2014 12:14:57 +0200 Subject: [PATCH 29/33] Replace 'warn' and 'exit' with 'abort' --- bin/dotenv | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bin/dotenv b/bin/dotenv index fcaf9a74..2bcacb7c 100755 --- a/bin/dotenv +++ b/bin/dotenv @@ -5,8 +5,7 @@ require 'dotenv' begin Dotenv.load! rescue Errno::ENOENT => e - warn e.message - exit 1 + abort e.message else exec *ARGV end From 8fb9768cb4002e7cb64324b2ee37811f718cea46 Mon Sep 17 00:00:00 2001 From: Jussi Virtanen Date: Fri, 7 Feb 2014 12:15:47 +0200 Subject: [PATCH 30/33] Handle missing arguments in 'dotenv' executable If the 'dotenv' executable is called without arguments, it fails with an ArgumentError. Handle this situation gracefully by exiting silently. --- bin/dotenv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/dotenv b/bin/dotenv index 2bcacb7c..ec295cbf 100755 --- a/bin/dotenv +++ b/bin/dotenv @@ -7,5 +7,5 @@ begin rescue Errno::ENOENT => e abort e.message else - exec *ARGV + exec *ARGV unless ARGV.empty? end From 5e1ae4e442f67d991b65044d965095fdc1beb497 Mon Sep 17 00:00:00 2001 From: Marshall Yount Date: Sat, 8 Feb 2014 08:53:29 -0600 Subject: [PATCH 31/33] Add ommited license to dotenv-rails.gemspec dotenv-rails.gemspec was missing the license directive. I set it to MIT, like the dotenv gem and the source repo itself. --- dotenv-rails.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/dotenv-rails.gemspec b/dotenv-rails.gemspec index 463d19c1..6ef242ea 100644 --- a/dotenv-rails.gemspec +++ b/dotenv-rails.gemspec @@ -8,6 +8,7 @@ Gem::Specification.new do |gem| gem.description = %q{Autoload dotenv in Rails.} gem.summary = %q{Autoload dotenv in Rails.} gem.homepage = "https://github.com/bkeepers/dotenv" + gem.license = 'MIT' gem.files = ["lib/dotenv-rails.rb"] gem.name = "dotenv-rails" From cedcba55e3dd43a85e0af61f7fc34bfda6fe104d Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 22 Feb 2014 09:38:40 -0500 Subject: [PATCH 32/33] Update changelog --- Changelog.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 2eccd414..25865519 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,14 +1,16 @@ # Changelog -## 0.10.0 - unreleased +## 0.10.0 - Feb 22, 2014 -* Add support for executing interpolated commands. +* 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] + set :dotenv_role, [:app, web] + +* Add `Dotenv.overload` to overwrite existing environment values. ## 0.9.0 - Aug 29, 2013 From 7b25dc91411f02941ea6d600c0b9171398ab4544 Mon Sep 17 00:00:00 2001 From: Brandon Keepers Date: Sat, 22 Feb 2014 09:39:16 -0500 Subject: [PATCH 33/33] Release 0.10.0 --- lib/dotenv/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dotenv/version.rb b/lib/dotenv/version.rb index b19ed3dc..3a69ad7a 100644 --- a/lib/dotenv/version.rb +++ b/lib/dotenv/version.rb @@ -1,3 +1,3 @@ module Dotenv - VERSION = '0.9.0' + VERSION = '0.10.0' end