Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

sinatra - Automatically load Dotenv on my ruby console

I'd like to automatically run Dotenv.load('.env.development') whenever I launch up a ruby console, it could either be from bundle console or alternatively irb. I'm using Sinatra, not Rails, and I'm not sure how to run some commands on console start.. I'd prefer to do this without a bash script, instead using the internal capabilities of the tools.. If there's a place to put ruby code on the start of a ruby console that would solve my issue and also allow for future console customization.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You try folliwing the documentation of gem(sorry my ignorance I don't know anything about sinatra)?:

Documentation dotenv

Install the gem:

$ gem install dotenv

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')

In your case i think should be:

require 'dotenv'
Dotenv.load('.env.development')

In ruby vanilla I dont know if possible, I think yes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...