-
-
Save will/722769 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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