The following code adds dataset methods to all models that have
columns of type datetime:

Sequel::Model.plugin :subclasses

Sequel::Model.descendents.each {|m|
  m.db_schema.each {|col, attr|
    if attr[:type] == :datetime
      method_name = (col.to_s.split('_').first + "_between").to_sym
      m.def_dataset_method(method_name) {|from_date, to_date|
        filter{(:created_at >= from_date) & (:created_at < to_date +
1)}
      }
    end
  }
}

So you can write Artist.created_between(Date.today-5, Date.today),
Artist.updated_between etc. if Artist has created_at, updated_at
columns.

I would like to package this code in a plugin but I am not sure how.
Looked at the source of several plugins but none of them did anything
similar. Would appreciate some advice on how to proceed.

Thanks

-- 
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