A lightweight singleton library for your Active Record models.
It just makes sense to store mutable, site-wide, admin-level settings in the database. Right? A key-value table may be more flexible, but maybe we don't want to be flexible!
If you truly want that flexibility: github.com/stephencelis/kvc
Lightning-fast queries! Doesn't get any faster than this! (Guaranteed.)
Follows the ultra-cool “singleton” pattern! (Tell your friends.)
What? That's not the “cool” singleton in Ruby? (Don't tell your friends?)
class HomepageSettings < ActiveRecord::Base include ActiveRecord::Singleton end
How Rubyish! Oh, you want it Railsish? Very well…
class HomepageSettings < ActiveRecord::Base acts_as_singleton end
Have your cake and eat your silly idiom, too! Just try to create a row!
HomepageSettings.instance # => #<HomepageSettings...>
Don't even try to access it otherwise. It won't work!
Active Record 2.3.2 or greater.
A delicate palate.
As a gem
# config/environment.rb config.gem "acts_as_singleton"
% [sudo] rake gems:install
As a plugin
% script/plugin install git://github.com/stephencelis/acts_as_singleton.git
Or, as a submodule:
% git submodule add git://github.com/stephencelis/acts_as_singleton.git \ vendor/plugins/acts_as_singleton
(The MIT License)
© 2009-2010 Stephen Celis, email@example.com.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.