Rails like Encrypted credentials for plain ruby with no dependencies.
Add to the application's Gemfile:
# Gemfile
gem "encrypted_credentials", github: "somleng/encrypted_credentials"
bundle exec edit_credentials
Paste the following:
production: &production
secret: "production-secret"
staging:
<<: *production
secret: "staging-secret"
# config/app_settings.yml
default: &default
foo: bar
secret: development-secret
production: &production
<<: *default
secret: "<%= app_settings.credentials.fetch('secret') %>"
staging:
<<: *production
secret: "<%= app_settings.credentials.fetch('secret') %>"
# config/app_settings.rb
require "encrypted_credentials/app_settings"
AppSettings = EncryptedCredentials::AppSettings.new(config_directory: File.expand_path(__dir__))
APP_ENV=production irb
require "bundler/setup"
require_relative "config/app_settings"
AppSettings.env
# "production"
AppSettings.fetch(:foo)
# "bar"
AppSettings.fetch(:secret)
# "production-secret"
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/somleng/encrypted_credentials.
The gem is available as open source under the terms of the MIT License.