[![Gem Version](https://badge.fury.io/rb/settingson.svg)](http://badge.fury.io/rb/settingson) # Settingson Settings management for Ruby on Rails 4 applications (ActiveRecord) ## Installation Add this line to your application's Gemfile: ```ruby gem 'settingson' ``` And then execute: ```console $ bundle ``` Or install it yourself as: ```console $ gem install settingson ``` ## Usage ```console rails g settingson MODEL ``` Replace MODEL by the class name used for the applications settings, it's frequently `Settings` but could also be `Configuration`. This will create a model (if one does not exist) and configure it with default options. Next, you'll usually run ```console rake db:migrate ``` as the generator will have created a migration file (if your ORM supports them). ## Example ```console rails g settingson Settings rake db:migrate ``` In rails console: ```ruby 2.1.1 :006 > Settings.hello.hello3.hello2 Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello' LIMIT 1 Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3' LIMIT 1 Settings Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3.hello2' LIMIT 1 => #> 2.1.1 :007 > Settings.hello.hello3.hello2 = 1 Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello' LIMIT 1 Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3' LIMIT 1 Settings Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3.hello2' LIMIT 1 (0.1ms) begin transaction SQL (5.2ms) INSERT INTO "settings" ("created_at", "name", "updated_at", "value") VALUES (?, ?, ?, ?) [["created_at", Sat, 03 May 2014 09:45:25 UTC +00:00], ["name", "hello.hello3.hello2"], ["updated_at", Sat, 03 May 2014 09:45:25 UTC +00:00], ["value", "--- 1\n...\n"]] (2.4ms) commit transaction => 1 2.1.1 :008 > Settings.hello.hello3.hello2 Settings Load (0.3ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello' LIMIT 1 Settings Load (0.2ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3' LIMIT 1 Settings Load (0.1ms) SELECT "settings".* FROM "settings" WHERE "settings"."name" = 'hello.hello3.hello2' LIMIT 1 => 1 ``` ## Contributing 1. Fork it ( https://github.com/daanforever/settingson/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request