Skip to content

A simple and straightforward object based settings solution that uses an ERB enabled YAML file and a singleton design pattern.

License

Notifications You must be signed in to change notification settings

mtyaka/settingslogic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Settingslogic

Settingslogic is an old library of mine that I decided to go ahead and share with the world. It’s nothing crazy or new. Just a simple solution to a simple problem. Settingslogic provides globally accessible settings via an ERB enabled YAML file. It has been great for my apps, maybe you will enjoy it too.

So here is my question to you.….is Settingslogic a great settings solution or the greatest?

* Documentation: settingslogic.rubyforge.org

Install and use

sudo gem install settingslogic

For rails, as a gem (recommended):

# config/environment.rb
config.gem "settingslogic"

Or as a plugin (for older versions of rails)

script/plugin install git://github.com/binarylogic/settingslogic.git

Create your settings

By default Settingslogic tries to load config/application.yml. This is just a typical YAML file, notice ERB is allowed.

# app/config/application.yml
defaults: &defaults
  cool:
    saweet: nested settings
  neat_setting: 24
  awesome_setting: <%= "Did you know 5 + 5 = " + (5 + 5) + "?" %>

development:
  <<: *defaults
  neat_setting: 800

test:
  <<: *defaults

production:
  <<: *defaults

Access your settings

>> RAILS_ENV
=> "development"

>> Settings.cool
=> "#<Settingslogic::Settings ... >"

>> Settings.cool.saweet
=> "nested settings"

>> Settings.neat_setting
=> 800

>> Settings.awesome_setting
=> "Did you know 5 + 5 = 10?"

Multiple settings

settings1 = Settings.new(:settings1) # looks for config/settings1.yml
settings2 = Settings.new("settings2.yaml") # looks for settings2.yml
settings2 = Settings.new("/abs/path/settings2.yaml") # looks for /abs/path/settings2.yml
settings3 = Settings.new(:some_setting => "some value")

Configure

Configuration is optional. See Settingslogic::Config for more details.

# config/initializers/settingslogic.rb
Settingslogic::Config.configure do |config|
  config.file_name = :config # will look for config/config.yml
  config.file_name = "config" # will look for config
  config.file_name = "config.yaml" # will look for confg.yaml
  config.file_name = "/absolute/path/config.yml" # will look for /absolute/path/config.yml
end

Copyright © 2008 Ben Johnson of Binary Logic, released under the MIT license

About

A simple and straightforward object based settings solution that uses an ERB enabled YAML file and a singleton design pattern.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published