# Scoped Proxy 1.0

**URL:** <https://www.ruby-forum.com/t/scoped-proxy-1-0/124027>\
**Category:** Ruby\
**Created:** [December 23, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/scoped-proxy-1-0/124027 "2007-12-23T19:00:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaspar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/5f8ce5/32.png) [@kaspar](https://www.ruby-forum.com/u/kaspar)\
**Post date:** [December 23, 2007, 7:00pm UTC](https://www.ruby-forum.com/t/scoped-proxy-1-0/124027/1 "2007-12-23T19:00:42Z")

</div>

== What?

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

== More!

Swiss.rb is a small project for a small country. Here we’ll release all  
sorts of small projects that we would not release otherwise - partly  
issued by the local ruby user group, partly things we develop for  
applications.

ScopedProxy is a small plugin for ActiveRecord that allows you to name  
a set of sql conditions (like role(‘admin’)) and then access it through  
that name. Really the logical consequence of with\_scope!

This latest version has default proxies that take effect when no other  
proxy is in effect. This is quite useful for always restricting search,  
not just when using a named proxy.

== Get your copy

[http://rubyforge.org/frs/?group\_id=5130](http://rubyforge.org/frs/?group_id=5130)

or maybe

gem install ScopedProxy

== Earlier Releases

Were on my old blog [neotrivium.com](http://neotrivium.com) - now we have an official project  
home ([http://rubyforge.org/projects/swissrb](http://rubyforge.org/projects/swissrb)), and one that isn’t so  
enterprisey 😉 Please let us know what you think! If you have something  
to contribute - please get in touch. Happy Hacking!

best greetings

Kaspar S.
