• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 16 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rails plugin that provides environment specific application configuration.

UPDATE¶ ↑

This project is no longer supported or maintained. It has been superceded by ConfigSpartan: github.com/cjbottaro/config_spartan

Summary¶ ↑

Application level configuration.

Features¶ ↑

* simple YAML config files
* config files support ERB
* config files support inheritance
* access config information via convenient object member notation

Basic Usage¶ ↑

You simply write a configuration file in YAML. Notice you can use ERB.

config.yml

aws:
  access_key: 123ABC
  secret_key: ABC123
now: <%= Time.now %>
servers: [ {name: example1.com}, {name: example2.com} ]

Then somewhere in your code, you create a global constant from the config file. Then access the config data via object member notation.

code

::AppConfig = ApplicationConfiguration.new("config.yml")
AppConfig.aws.access_key  # => "123ABC"
AppConfig.aws.secret_key  # => "ABC123"
AppConfig.now             # => Tue May 05 21:55:15 -0500 2009
AppConfig.servers[0].name # => "example1.com"

Inheritance¶ ↑

You can have a second config file that is recursively merged with the first config file.

base.yml

app_name:  MyCoolApp
domain:  dev.mycoolapp.com

production.yml

domain:  www.mycoolapp.com

code

::AppConfig = ApplicationConfiguration.new("base.yml", "production.yml")
AppConfig.app_name # => "MyCoolApp"
AppConfig.domain   # => "www.mycoolapp.com"

Using in a Rails app¶ ↑

You just need to create an initializer that looks something like this.

require 'app_config'
::AppConfig = ApplicationConfiguration.new(RAILS_ROOT+"/config/app_config.yml",
                                           RAILS_ROOT+"/config/environments/#{RAILS_ENV}.yml")

If you installed this as a Rails plugin instead of a gem, that code is already run for you in the plugin’s init.rb.

Environments¶ ↑

Alternatively to splitting out your environments into separate files, you can just have a single file which defines the application configuration for all environments (much like how databases.yml works). Note if you do this, nested configurations will not be recursively merged. See example below.

app_config.yml

defaults: &defaults
  one: won
  two: too
  nested:
    foo: foo
    bar: bar

development:
  <<: *defaults
  two: new
  nested:
    foo: bar

code

RAILS_ENV # => "development"
::AppConfig = ApplicationConfiguration.new("app_config.yml")
AppConfig.use_environment!(RAILS_ENV)
AppConfig.one # => "won"
AppConfig.two # => "new"
AppConfig.nested.foo # => "bar"
AppConfig.nested.bar # raises NoMethodError because nested configurations are not recursively merged

Author¶ ↑

Christopher J. Bottaro

More Repositories

1

param_protected

Filter unwanted params from your controllers/actions in your Rails app. Provides param_protected and param_accessible analogous to ActiveRecord's attr_protected and attr_accessible.
Ruby
85
star
2

schizo

DCI (data, context and interaction) for Ruby / Rails / ActiveRecord
Ruby
69
star
3

faktory_worker_ex

Elixir worker for Faktory
Elixir
67
star
4

has_easy

Easy access and creation of "has many" relationships for ActiveRecord models. It uses a "vertical table" so schema changes aren't necessary when you add fields. Use this plugin to add preferences, options, flags, etc to your models.
Ruby
55
star
5

tempest

Like Apache Storm, but smaller and for Elixir
Elixir
30
star
6

without_callbacks

Temporarily disable ActiveRecord callbacks.
Ruby
11
star
7

config_spartan

Super simple application configuration gem
Ruby
10
star
8

curly_mustache

ActiveRecord-like interface to various data stores (Memcached, Cassandra, Redis, Tokyo Tyrant). Implemented with ActiveModel.
Ruby
8
star
9

cream_ex

Cluster aware Memcached client for Elixir
Elixir
7
star
10

retryable_ex

Simple code retrying without metaprogramming
Elixir
7
star
11

docker_plugin_do_storage

DigitalOcean Storage plugin for Docker
Elixir
6
star
12

migration_izzle

Rails plugin to manage migrations when multiple developers are working on a shared database.
Ruby
5
star
13

ctrl

A simple flow control library similar to Flow or Step
CoffeeScript
5
star
14

em-xmlrpc-client

EventMachine + Fiber aware XMLRPC client
Ruby
4
star
15

ecto_pools_connection_cache

LRU connection cache that can connected to multiple databases via a single Repo
Elixir
4
star
16

paginate_izzle

Simple and flexible pagination using named scopes and partials.
Ruby
4
star
17

strand

Make fibers behave like threads using EventMachine.
Ruby
4
star
18

gnat

NATS Streaming (and plain NATS) client for Elixir
Elixir
4
star
19

preference_izzle

Robust preference plugin for Rails models.
Ruby
4
star
20

etcdctl-web

Web interface to etcd / etcdctl
Ruby
4
star
21

thread_storm

Simple thread pool with a few advanced features.
Ruby
4
star
22

fiber_storm

Thread pool pattern for evented (Eventmachine) fibers.
Ruby
4
star
23

thespian

Ruby implementation of actor pattern for use with threads and/or fibers
Ruby
3
star
24

kate_directory_project

Kate (KDE Advanced Text Editor) plugin that mimics TextMate's project functionality.
Python
3
star
25

object_logging

Super simple logging for objects.
Ruby
3
star
26

firefly_ex

Image/asset management for Elixir, heavily inspired by Ruby's Dragonfly
Elixir
2
star
27

shard_ex

Multitenancy with Ecto
Elixir
2
star
28

blog.stochasticbytes.com

My website
PHP
1
star
29

gen_server

Recreate Elixir's GenServer... in Ruby
Ruby
1
star
30

postgrex_replication

Elixir
1
star
31

task_tempest

Framework for creating queue based, threaded asychronous job processors.
Ruby
1
star
32

require_paranoia

Temporarily disable require to ensure thread safety.
Ruby
1
star
33

retrying_proxy

A simple gem to help you retry methods and deal with transient failures.
Ruby
1
star
34

configuration_dsl

Configure classes and objects using a DSL.
Ruby
1
star