Ok, got this working, got some stuff ported.  This post is just for
others' benefit.

In AR, named_scope can take a lambda{} which allows you to pass args
or do delayed eval:

  class Account < ActiveRecord::Base
    named_scope :of_type, lambda { |type_id|
      { :conditions => { :account_type_id => type_id } }
    }
    named_scope :recent, lambda { { :conditions => ['created_at > ?',
1.week.ago] } }
  end

And then:

  Account.of_type(ADMIN)
  Account.of_type(USER).recent

See also:

  
http://ryandaigle.com/articles/2008/3/24/what-s-new-in-edge-rails-has-finder-functionality
  http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/named_scope

In Sequel this is possible as well.  You can't use the subset()
shortcut though, you have to use def_dataset_method.

To pass args, simply make sure you tell def_dataset_method that your
do..end block needs an |arg|

  class Account < Sequel::Model
    def_dataset_method(:of_type) do |type_id|
      filter(:account_type_id => type_id)
    end
    def_dataset_method(:recent) do
      filter(:created_at => 1.week.ago)
    end
  end

And then:

  Account.of_type(ADMIN).all
  Account.of_type(USER).recent.all

Remember you need the .all explicitly, unlike ActiveRecord.

-Nate

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to