Skip to content

Instantly share code, notes, and snippets.

@slaskis
Created October 12, 2009 01:55
Show Gist options
  • Save slaskis/208056 to your computer and use it in GitHub Desktop.
Save slaskis/208056 to your computer and use it in GitHub Desktop.
class User
include DataMapper::Resource
has 1, :event
default_scope.update( :order => [ :priority.desc ] )
property :username, String, :key => true, :unique => true
property :name, String, :length => 255
property :email, String, :length => 255
property :phone, String, :length => 255
property :work, String, :length => 255
property :work_url, String, :length => 255
property :avatar_url, String, :length => 255
property :twitter, String, :length => 255
property :blurb, Text
property :lat, Float
property :lng, Float
property :priority, Integer, :default => 0
property :moving, Boolean, :default => false
after :save do
if @eid
event ||= Event.create( :eid => @eid , :user_username => username )
@eid = nil
save
end
end
def eid=(id)
@eid = id
end
end
class Event
include DataMapper::Resource
belongs_to :user
has n, :streams
default_scope.update( :order => [ :start_time.desc ] )
property :id, Serial
property :eid, String
property :name, String, :length => 255
property :tagline, String, :length => 255
property :start_time, Integer
property :end_time, Integer
property :location, String, :length => 255
property :description, Text
end
class Stream
include DataMapper::Resource
belongs_to :event
default_scope.update( :order => [ :uploaded_at.desc ] )
property :id, Serial
property :stream_id, String
property :state, Enum[ :live , :archived ]
property :title, String, :length => 255
property :preview, String, :length => 255
property :uploaded_at, DateTime
property :updated_at, DateTime
property :created_at, DateTime
def created=(at)
self[:uploaded_at] = Time.at(at.to_i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment