Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
ActsAsRanged ============ This acts_as deals with records that have a start and stop column. Specifically, it provides the ability for a new record to be overlaid on top of existing records in a way that preserves the content of the new record, but merges, adjusts or deletes existing records that are either adjacent to, overlap, or are subsumed by the new record. The overlaying is done with the overlay method. It's possible to make it so that the act of saving a record automatically does the overlay. I chose not to because (at this hour) that seems like "too much magic." I'd prefer to draw attention to the non-standard thing being done by using a non-standard name than to have "the right" thing automatically happen in a way that hides what's being done. Overlaying is done via the overlay! method (the exclamation point at the end is a warning; records other than your own my be affected by the overlay). Deleting ranges is done by the delete_range method (no exclamation point, because deletion inherently alters other records). Example ======= Consider a model that has three fields: color, start and stop. We'll start out with two instances: start: 0 stop: 5 color: red start: 5 stop: 10 color: black If we overlay a new record start: 2 stop: 7 color: green then we'd lose some of the red and some of the black and get start: 0 stop: 2 color: red start: 2 stop: 7 color: green start: 7 stop: 10 color: black If we then overlaid another new record start: 0 stop: 7 color: white we'd totally overwrite all of the red and green and wind up with start: 0 stop: 7 color: white start: 7 stop: 10 color: black If we then overlaid another new record start: 5 stop: 7 color: black we'd merely merge the new record into the existing black record and get start: 0 stop: 5 color: white start: 5 stop: 10 color: black Copyright (c) 2010 Jackrabbit Systems, LLC; released under the MIT license Written by Cliff Matthews, email@example.com.