Ain’t Release Early, Release Often wonderful ? I just received a patch from Evgeniy Pirogov that makes the failing test from the AutoScope plugin work.

Evgeniy’s patch is available here, but you should simply svn or piston update to get the latest version, since I eagerly accepted Evgeniy’s patch.

Thank you, Evgeniy for your work.

Well, in relation to my Useful #with_scope technique post, here’s a plugin that implements that idea. This code is used on a production system. It works perfectly for my needs at the moment.

AutoScope

Automatically create scoped access methods on your ActiveRecord models.

Examples

Declare your scopes within your ActiveRecord::Base subclasses.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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:
1
2
3
4
Testimonial.approved.count
Testimonial.unapproved.create!(params[:testimonial])
@young_contacts = Contact.young
@contacts = Contact.old.find(:all, :conditions => ["name LIKE ?", params[:name]])

The plugin’s home page is: http://xlsuite.org/plugins/auto_scope The plugin’s Subversion repository is: http://svn.xlsuite.org/plugins/auto_scope

 

Search

A picture of me

I am François Beausoleil, a Ruby on Rails coder. During the day, I work on XLsuite. At night, I am interested many things. Read my biography

Tags

(3) (1) (0) (2) (1) (1) (2) (2) (1) (2) (1) (2) (1) (2) (1) (1) (1) (1) (2) (14) (1) (1) (1) (1) (2) (1) (1) (2) (0) (1) (2) (1) (3) (1) (1) (1) (1) (1) (1) (0) (3) (2) (1) (2) (2) (1) (3) (2) (8) (8) (9) (12) (1) (1) (3) (1) (1) (1) (1) (1) (1) (2) (2) (2) (1) (1) (3) (1) (3) (1) (0) (23) (1) (1) (0) (1) (1) (1) (23) (25) (1) (1) (13) (1) (1) (2) (3) (1) (1) (4) (1) (2) (3) (0) (1) (7) (3) (1) (5) (5) (2) (2) (2) (4) (6) (7) (1) (0) (1) (1) (2) (2) (1) (4) (12) (2) (1) (2) (4) (1) (1) (1) (2) (8) (2) (3) (2) (2) (1) (3) (1) (1)

Links

Projects I work on

Categories

Archives