Skip to content

Instantly share code, notes, and snippets.

@will
Forked from roryfranklin/gist:614916
Created December 1, 2010 01:23
Show Gist options
  • Save will/722769 to your computer and use it in GitHub Desktop.
Save will/722769 to your computer and use it in GitHub Desktop.
require 'rubygems'
if ARGV[0] == 'old'
puts 'beta7'
gem 'couchrest_model', '1.0.0.beta7'
require 'couchrest_model'
else
puts 'head'
$:.unshift 'lib'
require File.join(File.dirname(__FILE__),'lib', 'couchrest_model')
end
DB = CouchRest.database!("test")
class Event < CouchRest::Model::Base
use_database DB
property :event_type, :type => String
property :actioner_id, :type => String
property :event_date, :type => String
property :event_parent, :type => String
property :event_hierarchy, :type => [String], :default => []
property :old_state
property :new_state
view_by :event_date
view_by :event_parent
validates_presence_of :event_type
validates_presence_of :event_date
before_save :convert_date
def linked_events
events = Event.by_event_parent(:key => self.id)
end
def is_linked?
!self.event_parent.blank?
end
def parent
parent_event = Event.get(self.event_parent)
parent_event
end
private
def convert_date
self.event_date = Time.parse(event_date.to_s)
end
end
(1..100).each do |i|
Event.create!(:event_type => "CREATE_PARTITION_#{i}", :event_date => Time.now)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment