Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 912 Bytes

README.md

File metadata and controls

60 lines (40 loc) · 912 Bytes

Rails Typed Settings

Implements cached database stored settings for rails. Settings are typed. You can't set a boolean setting to an integer.

Setup

Add to your Gemfile:

gem "rails_typed_settings"

Generate migration:

$ rails g rails_typed_settings:install

Migrate your database:

$ rake db:migrate

Usage

Add a app/services/settings.rb file with contents:

class Settings < RailsTypedSettings::Base
  setting :sale, :boolean, :default => false
  setting :sale_discount, :float, :default => 0.3
  setting :sale_name, :string
end

Reading a setting:

Settings[:sale]

Writing a setting:

Settings[:sale] = true

Get list of all settings

Settings.keys   # [:sale, :sale_discount...]

Limitations

Because of the way its built you cannot store nil/null as settings values

This project rocks and uses MIT-LICENSE.