Project

confie

0.0
No commit activity in last 3 years
No release in over 3 years
Minimalistic settings for your Rails application
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

confie

Minimalistic settings for your Rails application

Features

  • super-simple
  • loads YAML+ERB files
  • reloads every time on Object.send(:remove_const, :Settings)
  • uses Hashie::Mash

Installation

Add gem 'confie' in your Gemfile

Usage

Accessing settings keys

# config/settings.yml
my:
  config_key1: "value"
  config_key2: [1, 2, 3]
other_key: 2
Settings # #<Hashie::Mash my=#<Hashie::Mash config_key1="...>>
Settings.my.config_key1 # "value"
Settings.my.config_key2 # [1, 2, 3]
Settings.other_key # 2
# change yml file
Object.send(:remove_const, :Settings)
Settings.other_key # 3

Files priority

Every next file overrides values from previous using deep merge

  • #{Rails.root}/settings.yml
  • #{Rails.root}/settings.local.yml
  • #{Rails.root}/settings/#{Rails.env}.yml
  • #{Rails.root}/settings/#{Rails.env}.local.yml

Defining const

To redefine settings constant, e.g. MyConfig, create my_config.rb in your autoloaded directory

# my_config.rb
MyConfig = Confie.load!

# then use it
MyConfig.my_key

Extending existing module

# config/settings.yml
secret_key: "abcdef"
module Twitter; end
Confie.extend!(Twitter)
Twitter.settings.secret_key # "abcdef"

Reload every request in development mode

# in config/initializers/
ActiveSupport::Dependencies.explicitly_unloadable_constants << 'Settings'