ProductPromotion
Logo

Ruby

made by https://0x3d.site

GitHub - varvet/econfig: Flexible configuration for Ruby applications
Flexible configuration for Ruby applications. Contribute to varvet/econfig development by creating an account on GitHub.
Visit Site

GitHub - varvet/econfig: Flexible configuration for Ruby applications

GitHub - varvet/econfig: Flexible configuration for Ruby applications

Econfig

Econfig is a gem which allows you to easily configure your Ruby applications in a multitude of ways.

This project is not actively maintained!

We at Varvet are not currently using this gem and are not actively maintaining it. We will gratefully accept pull requests which fix bugs or update dependencies, but not functional changes.

Installation

Add this to your Gemfile:

gem "econfig"

If you're using Rails, you'll want to require the Rails extension:

gem "econfig", require: "econfig/rails"

Accessing config options

Extend your main application module with the Econfig shortcut.

In Rails, you'll want to add this in config/application.rb:

module MyApp
  extend Econfig::Shortcut

  class Application < Rails::Application
    # …
  end
end

In a modular Sinatra application, extend your controller class and copy its settings to Econfig in app.rb:

require 'sinatra'
require 'econfig'

class MyApp < Sinatra::Base
  extend Econfig::Shortcut

  Econfig.env = settings.environment.to_s
  Econfig.root = settings.root

  # …
end

In either case, you can now you can access configuration like this:

MyApp.config.aws_access_key_id

If the key you accessed is not configured, Econfig will raise an error. To access optional configuration, which can be nil, use brackets:

MyApp.config[:aws_access_key_id]

Sometimes you might want to bypass the strictness requirement in econfig, for example if you're running the application as part of a build process. In that case you can set the environment variable ECONFIG_PERMISSIVE, and econfig will not raise errors on missing keys, instead returning nil.

Configuring options.

You can specify configuration through:

  1. ENV variables
  2. Redis
  3. Relational database
  4. YAML files
  5. OSX Keychain

This allows you to set up Econfig on most kinds of hosting solutions (EngineYard, Heroku, etc) without any additional effort, and to switch between them easily.

ENV variables

Just set an environment variable whose name is the name of the option being accessed uppercased.

For example:

AWS_ACCESS_KEY_ID=xyz rails server

You can now read it like this:

MyApp.config.aws_access_key_id # => "xyz"

This is especially convenient for Heroku.

YAML

Add a yaml file to config/app.yml. This should have a similar layout to config/database.yml:

development:
  aws_access_key_id: "xyz"
  aws_secret_access_key: "xyz"
production:
  aws_access_key_id: "xyz"
  aws_secret_access_key: "xyz"

Econfig also reads configuration from config/secret.yml which is the new standard for secret configuration parameters in Rails 4.1.

Relational database

This needs to be explicitly enabled. In config/application.rb add this code:

require "econfig/active_record"
Econfig.backends.insert_after :env, :db, Econfig::ActiveRecord.new

You probably want environment variables to take precendence over configuration from ActiveRecord, hence the insert_after. If you'd rather have ActiveRecord configuration take precendence you can use this instead:

require "econfig/active_record"
Econfig.backends.unshift :db, Econfig::ActiveRecord.new

You will also need to create a migration to create the necessary database tables:

rails generate econfig:migration
rake db:migrate

Redis

This needs to be explicitly enabled. In config/application.rb add this code:

require "econfig/redis"
redis = Redis.new(:host => "myredis.com")
Econfig.backends.insert_after :env, :redis, Econfig::Redis.new(redis)

If you wish to namespace your keys in Redis, you can use redis namespace.

OSX Keychain

For the OSX keychain backend, see econfig-keychain.

Setting values

You can set options by simply assigning them:

MyApp.config[:aws_access_key_id] = "xyz"

This will set the value in the default write backend, which by default is :memory. This means that by default, configuration which is set like this is not persisted in any way.

If you always want to assign values to a different backend, for example the database backend, you can set the default write backend like this:

Econfig.default_write_backend = :db

You can also explicitly supply the backend when setting a configuration value:

MyApp.config[:db, :aws_access_key_id] = "xyz"

License

MIT, see separate LICENSE.txt file

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory