diff --git a/lib/vagrant-env/config.rb b/lib/vagrant-env/config.rb index ab59f37..f8a79c9 100644 --- a/lib/vagrant-env/config.rb +++ b/lib/vagrant-env/config.rb @@ -3,11 +3,33 @@ module VagrantPlugins module Env class Config < Vagrant.plugin("2", :config) - attr_accessor :enable - def initialize - @enable = UNSET_VALUE - Dotenv.load + + # Simple interface: + # config.env.enable __FILE__ + def enable(vagrantfile = nil) + if vagrantfile + load File.dirname(vagrantfile) + '/.env' + else + # The default is .env in the current directory - but that may not be + # the same directory that the Vagrantfile is in + # https://github.com/gosuri/vagrant-env/issues/2 + load + end + end + + # Lower-level methods - proxy to Dotenv: + def load(*filenames) + Dotenv::load *filenames + end + + def load!(*filenames) + Dotenv::load! *filenames + end + + def overload(*filenames) + Dotenv::overload *filenames end + end end end