Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A lightweight singleton library for your Active Record models.

branch: master
README.rdoc

acts_as_singleton

github.com/stephencelis/acts_as_singleton

DESCRIPTION

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

FEATURES/PROBLEMS

  • 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?)

SYNOPSIS

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!

REQUIREMENTS

  • Active Record 2.3.2 or greater.

  • A delicate palate.

INSTALL

As a gem

Configure:

# config/environment.rb
config.gem "acts_as_singleton"

And install:

% [sudo] rake gems:install

As a plugin

Traditional:

% 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

LICENSE

(The MIT License)

© 2009-2012 Stephen Celis, stephen@stephencelis.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.

Something went wrong with that request. Please try again.