Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deekor/site_variables
Generates a YAML file you can populate to create ENV specific site wide variables. Inspired by the old rails secrets.yml
https://github.com/deekor/site_variables
environment-variables gem rails rails5 variables
Last synced: 17 days ago
JSON representation
Generates a YAML file you can populate to create ENV specific site wide variables. Inspired by the old rails secrets.yml
- Host: GitHub
- URL: https://github.com/deekor/site_variables
- Owner: Deekor
- License: mit
- Created: 2018-10-08T00:44:50.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-08T03:19:25.000Z (about 6 years ago)
- Last Synced: 2024-10-17T09:46:14.903Z (about 1 month ago)
- Topics: environment-variables, gem, rails, rails5, variables
- Language: Ruby
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# SiteVariables
Over the years I have become accustomed to using the Rails `secrets.yml` file as a nice config file for any non-sensitve constant variables I'd like to use throughout my application. With Rails 5.2 `secrets.yml` is now removed in favor of encrypted credentials. Overall this is a good thing as it was bad practice to store and commit any sensitive variables into `secrets.yml`.The [site_variables](https://rubygems.org/gems/site_variables) gem allows me to continue my practice of using a YAML file for environment specific non-sensitive variables.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'site_variables'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install site_variables
## Usage
After installation run:
$rails generate site_variables
This gives us two files:1. `config/initializers/site_variables.rb`
2. `config/site_variables.yml`The important file is `site_variables.yml`
Edit the YAML file with the variables you would like to use. Any environment specific variables (in the `development` or `production` sections for example) will override any variables in the `shared` section.You now can access your hash of site variables inside your Rails app with the `SITE_VARIABLES` constant.
### Example
`config/site_variables.yml`:
```
shared:
base_url: this will be overriden by the environments
site_name: My Awesome Site
support_email: [email protected]development:
base_url: https://somengroksubdomain.ngrok.ioproduction:
base_url: https://myawesomesite.com
```In a view:
```
Welcome to <%= SITE_VARIABLES['site_name'] %>
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/deekor/site_variables. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the SiteVariables project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/deekor/site_variables/blob/master/CODE_OF_CONDUCT.md).