-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add better configuration handling #2
Comments
I think this approach might work well: https://gist.github.com/jcamenisch/b878c667a894f4d903a2 |
I don't know, this may be overkill. I think if we just always call I would like it to throw at boot time though. |
Do you have any simpler/lighter suggestions? One idea: just assign ENV variables to Rails.configuration in application.rb. Downside: This would de-emphasize the difference between environment-specific stuff and other configurations. Another idea: just assign each env variable to a Ruby constant at boot time, like AIRBRAKE_API_KEY = ENV['AIRBRAKE_API_KEY'] || '' # 'see http://airbrake.io/'
WIDGET_PRICE = ENV.fetch('WIDGET_PRICE').to_d # The price for one widget This would accomplish almost everything we'd want, but wouldn't be quite as helpful in forcing everyone into the right practices. You could also do it this way, but that relies too heavily on discipline for my taste. It also doesn't provide the self-documentation benefits for each variable. |
I almost like the last way. Either that or parse over the .env.example and raise if any are missing. On Sat, Nov 23, 2013 at 8:17 AM, Jonathan Camenisch
|
I had this same issue for the PHP version of dotenv I made. I added a The Dotenv::load(__DIR__);
Dotenv::required(array('DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS')); Maybe we could do something similar, or contribute this to the dotenv Ruby gem too? |
@vlucas that'd be nice On Sat, Nov 23, 2013 at 2:10 PM, Vance Lucas [email protected]:
|
Dotenv is for development. I'm pretty sure they wouldn't accept a PR that's
|
This started with the statement that 48 lines of Ruby was overkill, and now
|
I think I made a mistake here when I included the functionality to specify To let you know how that got in there, I was looking at some other Optparse takes a class parameter, and converts the supplied parameter to it. I'd rip that out for you to see, but that sounds like a pain to do on my So, this was me playing with some ideas. The API doesn't seem to be hitting |
Good point. All the if(BULLET_ENV !== 'production') {
Dotenv::load(__DIR__);
}
Dotenv::required(array('DB_HOST', 'DB_NAME', 'DB_USER', 'DB_PASS')); So dotenv is still loaded as a dependency, but it's not loading and parsing a .env file on each request. |
This is what the Cfg module looks like without the class conversion functionality: https://gist.github.com/jcamenisch/b878c667a894f4d903a2 —29 total lines instead of 48. |
Still way confusing. I was thinking something simple like: Edit: Looks like that doesn't work. The proper way to get the Also the way I was doing the array subset check won't work. It could be done via: Working it out a little more: missing_vars = Dotenv::Environment.new('.env.example').keys - ENV.keys
raise "Missing ENV vars: #{missing_vars}" if missing_vars.any? This SO question has a couple other ways to do it. |
We don't want everything in .env.example to be required. Some things can What part is confusing? The usage or the implementation? You don't really
|
I don't really like the use of a And the implementation is confusing. I don't see why we should just ignore the implementation and not review it. |
I don't particularly have a recommendation for adding optional variables aside creating a |
Really if we just start using the convention of |
That doesn't keep a broken app from booting in production |
The reason for using Object-oriented programming is "encapsulation," which means packaging up some logic so you can reuse it over and over again without having to think again about how it works. In this case, we need to accomplish a few things:
Given those requirements, we could do the "simple" thing, and agree on a few standard practices. Once we establish those practices, all we have to do is communicate them to everyone, including those who join the project in the future, and then just remember to always be good little programmers and follow our best little practices that are written down in some README somewhere. Being a lazy programmer, with a horrible memory, who spends half my day just trying to remember where I/we put stuff, the above paragraph sounds like pain. The alternative is to separate out the tedious parts that don't require an actual mind, and delegate those parts to a small bit of code that will do them for us. We could write the code in such a way that it's impossible to forget the stuff we need to do ourselves, and it's pleasant when we do it.
When you encapsulate something in library code, the idea is that you stop thinking about how it works and just use it. When you write the library, code review is great, and I'm all for it. However, it seems like that is clouding this discussion, and you're proposing things like using If we don't want some object other than ENV, we could monkey patch ENV to do all this work for us. Or, we could name our object in a way that might be less confusing to you, like |
I will say, this solved the "don't deploy a broken app" problem beautifully for me in Sounding Board. I pushed some code to Heroku without setting a few needed environment variables, and it refused to boot the new slug, giving me an error message that was easy to understand. I configured the missing variable, and deployed again until I got them all (or finally caved in and compared the whole list from |
I guess we could always just use this: https://github.com/jcamenisch/ENV_BANG |
When you replied with your thought out reply (13 days ago), I wanted to respond to it in whole but didn't have a chance to at the time. For the most part I agreed but didn't like adding the extra file to the project. For some reason as a gem, I like the solution. Proceed. |
Oh, cool. Thanks for letting me talk (argue?) that out. |
Goals:
The text was updated successfully, but these errors were encountered: