Skip to content

kaomte/rails_typed_settings

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published