# \[ANN\] AutoScope Plugin

**URL:** <https://www.ruby-forum.com/t/ann-autoscope-plugin/90422>\
**Category:** Rails\
**Created:** [March 28, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/ann-autoscope-plugin/90422 "2007-03-28T17:25:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fbeausoleil](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@fbeausoleil](https://www.ruby-forum.com/u/fbeausoleil)\
**Post date:** [March 28, 2007, 5:25pm UTC](https://www.ruby-forum.com/t/ann-autoscope-plugin/90422/1 "2007-03-28T17:25:20Z")

</div>

= XlSuite::AutoScope

Automatically create scoped access methods on your ActiveRecord models.

== Examples  
Declare your scopes within your ActiveRecord::Base subclasses.

class Contact \< ActiveRecord::Base  
auto\_scope   
:old =\> {:find =\> {:conditions =\> [“born\_on \< ?”,  
30.years.ago]}},  
:young =\> {:find =\> {:conditions =\> [“born\_on \> ?”, 1.year.ago]}}  
end

class Testimonial \< ActiveRecord::Base  
auto\_scope   
:approved =\> {  
:find =\> {:conditions =\> [“approved\_at \< ?”, proc  
{Time.now}]},  
:create =\> {:approved\_at =\> proc {Time.now}}},  
:unapproved =\> {  
:find =\> {:conditions =\> “approved\_at IS NULL”},  
:create =\> {:approved\_at =\> nil}}  
end

These declarations give you access to the following scoped methods:  
Testimonial.approved.count  
Testimonial.unapproved.create!(params[:testimonial])  
@young\_contacts = Contact.young  
@contacts = Contact.old.find(:all, :conditions =\> [“name LIKE ?”,  
params[:name]])

= More Information

Blog:  
[http://blog.teksol.info/articles/2007/03/28/autoscope-plugin-automatic-scopes-for-your-needs](http://blog.teksol.info/articles/2007/03/28/autoscope-plugin-automatic-scopes-for-your-needs)  
Plugin home: [http://xlsuite.org/plugins/auto\_scope](http://xlsuite.org/plugins/auto_scope)  
Subversion: [http://svn.xlsuite.org/plugins/auto\_scope/](http://svn.xlsuite.org/plugins/auto_scope/)

## Enjoy !

François Beausoleil  
[http://blog.teksol.info/](http://blog.teksol.info/)  
[http://piston.rubyforge.org/](http://piston.rubyforge.org/)
