ScopedProxy

== SUMMARY

Finally, long awaited, scoped proxies as a release. Which you say. Admitted, there are about 15 plugins
that are called scoped_proxy, but only one comes with a full suite of tests that is full 40 lines longer
than the actual code. That is the scoped proxy you are looking at. It is y2k compliant and works as a gem.
Magnificent, isn't it?

This gem is all about simplicity; you won't find a whole toolbox here, just another valued screwdriver.
But we happen to encounter a lot of screws - hopefully you do too - and find this very useful. If you
want to skip all this summary that is really longer than all the other texts in this release, have a look
at the synopsis below.

== SYNOPSIS:

Allows storing scopes as names; that way you can address subsets of your model space by meaningful names.

require 'scoped_proxy' # Railsers: You might want to call this in environment.rb

class User < ActiveRecord::Base
scoped_proxy :role do |role|
{
:find => { :conditions => ['role = ?', role] }
}
end
scoped_proxy :deleted, :find => {
:conditions => 'deleted_at is not null'
}
end

admins = User.role('admin')
admins.count # => 12
admins.find(:all) # => [ ... ]

User.deleted.count # => a number

This implementation also brings (NEW, SHINY) default proxies. That means you can have a proxy in effect
when no other proxy is in effect.

class User < ActiveRecord::Base
default_proxy :find => { :conditions => 'deleted_at is null' }
end

User.find(:all) # only finds users that aren't deleted

== REQUIREMENTS:

* gem install metaid

== TESTING

If you want to run the rspec tests, you must have a database on localhost called 'test' and a user
called 'developer' that is allowed to (write)access it. Caution: running the tests will delete at least
your 'users' table in said database. But I hope you wouldn't run this on production, nor call your
production database 'test'. Warned you.

Details can be changed in spec/spec_helper.rb

== THANKS

Special Thanks to Florian Hanke (florian at restorm dot com) and Severin Schoepke (severin at restorm dot com).
They have played an enormous role in keeping this mean and lean. Thanks also to the rest of the gang - please
visit us at labs.restorm.com.

== CONTACT

Rubyforge Project:

http://rubyforge.org/projects/swissrb

Documentation:

upcoming...

Bugs:

http://rubyforge.org/tracker/?atid=19774&group_id=5130&func=browse


== LICENSE:

(The MIT License or the Ruby License, choose)

Copyright (c) 2007 Kaspar Schiess, all rights reserved

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.