Recurring Events feature set

Hi all, I'm a J2EE developer by day and I'm moonlighting to migrate my church's website to a Rails application.

One of the fundamental abstractions that any organization needs to track is events. Events could be work schedules, pay cycles, meetings and so forth. Events recur, of course. I would like to brainstorm with you about possible solutions.

So on that note, I started to think about how to develop an events feature set for a Rails application. Some of constraints I have is that since this is fundamental to my organization's process, we need to save Events with ActiveRecord into our database. (So I doubt Google Calendar would work but I could be convinced otherwise). Events at least have a title, description, start time and end time. But they also recur. Here's where I get puzzled.

a) First solution: browse through the Outlook API (via MSDN) and reconstruct the classes that make up RecurrenceType and RecurrencePattern. RecurencePattern has child classes such as RecursMonthly, RecursDaily, and RecursMonthlyNth. It seems like the right kinds of abstraction for a helper class or a module. Perhaps it isn't Rubyesque but refactoring can fix that problem.

The more important thing that bothers me about this set of classes is that it doesn't seem appropriate to make them ActiveRecord classes. It's just too busy with nouns, because subtypes of RecurrencePatterns are manifold. I personally might have to support a RecurrencePattern for every other Easter! Still an event has to be persisted with some sort of recurrence pattern.

b) Next solution: I'm wondering if it would be appropriate to use a RecurrencePattern hierarchy as a wrapper around the cron expression. Cron expressions would be persisted to the database. If an Event has a cron expression, we need to be able interpret the expression with intermediate classes so that a user can set the recurrence properties of the cron expression. The intermediate classes need to mediate in both directions between the UI (a la Outlook's API) and the database (cron expression).

Like any lazy programmer, I thought there might be a plugin or gem available. A quick search this morning turns up inactive Ruby gems to do cron expressions. A search on plugins turns up little. Does anyone know if any resource that could be reused?

So I might have to do it myself. Writing the classes would take a lot of work but seems worthwhile. So worthwhile I wonder about mixing them in to Date or Time a la ActiveSupport. Has anyone attempted to do this?

Regards, Alan

Does runt (http://runt.rubyforge.org/) look interesting ?

Fred

Fred, I'll probably try the Runt gem. It's definitely an improvement over the .Net API because it provides a pattern language.

Here are my thoughts.

Though after browsing the RDoc, I noticed that neither Runt::TExpr nor Runt::Schedule provide a trivial way to persist their state to a database with the important constraint that one can reconstruct the object from the database. To be more specific about what I'm looking for, both of them have methods that will return an array of dates (not bad), but if one loads an array of dates (via ActiveRecord) from the database created by Runt::Schedule, one cannot reconstruct a Runt::Schedule or object.

The reason that this may be a useful is that one might want to present the temporal expression in the UI using a set of forms (just as Outlook does).

Perhaps this is functionality that needs to be added to a gem that hasn't reached 1.0 state. I'm inclined to allow a ::Schedule to have a CronExpression object can returns a cron expression, which can be persisted as a string. CronExpression could parse a cron expression into a ::Schedule object.

Or perhaps, in the spirit of YAGNI, it ain't bad for the client to always recreate a new schedule everytime they change a recurring event.

-Alan

@Alan: For a similar situation I used an ARec model that was composed_with the TExpr/Schedule object.

Andy -

@Alan: For a similar situation I used an ARec model that was composed_with the TExpr/Schedule object.

Did you serialize?

Am confused by your "composed_with" syntax - a plugin? I can't find

I have solved this problem with serialization - but not the cleanest - nor the most efficient when processing large amounts of appointments. Have considered going towards an ical model to store them (erd is out there somewhere) - but not quick solution.

thanx - Jodi

Andy -

@Alan: For a similar situation I used an ARec model that was composed_with the TExpr/Schedule object.

Did you serialize?

Am confused by your "composed_with" syntax - a plugin? I can't find

composed_of: Peak Obsession

Fred

Frederick -

Sorry, not enough Starbucks this morning... :slight_smile:

Would you mind sharing your composed_with solution? It sounds very interesting.

Thanks