Manage all project environment variables at one place using Gem Figaro

1. Engine

  • I am currently participating in a Rails project and feel very excited to learn and learn new knowledge after a long time without touching.
  • Due to the fact that over the past year has not directly touched the code, I pay more attention to the techniques to make the project start and happen in a smoother and smoother way.
  • A project Rails always has a lot of information that needs to be hidden at the local and not to let outsiders know, how to manage it effectively is something I have to worry about until I know about Gem Figaro .
  • Using Figaro gem can help you standardize all participating projects easily

2. Workflow if NOT using Figaro

Basically a Rails project in Framgia, when you start you have to do the following:

  1. Create a Rails project with rails new
  2. Add database.yml to .gitignore , then duplicate this file to create fie template database.yml.example
  3. Since it is necessary to have a secret key for the Rails app, after using rake secret create a key, please pity into the config folder to create secrets.yml.template (yes, template), duplicate this file to create the secrets.yml file, fill in the required information. Set it and then put this file in .gitignore to hide it.
  4. In addition, there are many other environment variables like secret key for devise, information about email account will be used to shoot mail …

3. Workflow if using Figaro

  1. Check out the documentation about gem Figaro. Using:
    • add figaro to Gemfile
    • bundle install
    • bundle exec figaro install
    • Yes, it is simple in 3 basic steps, 1 file named application.yml has been created for you and this file is automatically added to the .gitignore . Due to the standard yml, the addition of key and value fields is very familiar, in addition to the calling method can not be simpler than ENV["{tên_key}"] or Figaro.env.{tên_key} . End
  2. If this is the first time, please create any folder, which will contain the database.yml , secrets.yml , application.yml.example that you standardize to use in all projects from now on. .
    For example:

    • database.yml
    • secrets.yml
    • application.yml.example
  3. Copy the three files into the project config folder (the file application.yml.example – will help other teammates easily set up the project environment variable)
  4. Fill in the required information into the application.yml file according to the format of application.yml.example .
  5. Everything is ready for you.

4. Conclusion

According to the Convention over configuration concept of Rails, standardizing and helping dev not lose in thinking and making many decisions (without reducing the flexibility of the project) is my idea when deciding to come to Figaro. By using Figaro, it will help you start a project easily and help it take less time, standardize projects as well as the most important thing is to have an effective management place to help you not worry. Thinking about managing important variable information in the project according to the environment. This is just an idea presentation and hope you have some interest in Figaro, more details you can see on Github's gem.

5. Problems encountered

This is just a small problem, but I have encountered it when using Rubymine. Rubymine integrates the database connection of your IDE project, based on database.yml file to login to the db always. However, I have added these parameters to application.yml so I have a login error. May the Rubymine talents correct soon.

Thank you for watching the article

ITZone via Viblo

Share the news now