From 6c1bd3d30c433159fced61b1cd4f8ea1973a84c4 Mon Sep 17 00:00:00 2001 From: Winfield Peterson Date: Thu, 5 Jan 2012 16:05:03 -0500 Subject: [PATCH] Document new suppress_errors option. --- README.rdoc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+), 0 deletions(-) diff --git a/README.rdoc b/README.rdoc index 4be7030..b5cf263 100644 --- a/README.rdoc +++ b/README.rdoc @@ -114,6 +114,22 @@ Modifying our model example: This would allow you to specify a custom value for per_page just for posts, or to fall back to your default value if not specified. +=== 4. Suppressing Exceptions Conditionally + +Raising exceptions for missing settings helps highlight configuration problems. However, in a +Rails app it may make sense to suppress this in production and return nil for missing settings. +While it's useful to stop and highlight an error in development or test environments, this is +often not the right answer for production. + + class Settings < Settingslogic + source "#{Rails.root}/config/application.yml" + namespace Rails.env + suppress_errors Rails.env.production? + end + + >> Settings.non_existent_key + => nil + == Note on Sinatra / Capistrano / Vlad Each of these frameworks uses a +set+ convention for settings, which actually defines methods -- libgit2 0.21.0