Created
June 9, 2011 15:13
-
-
Save jmaicher/1016933 to your computer and use it in GitHub Desktop.
Playing with streama
This file contains 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
class Activity | |
include Mongoid::Document | |
include Streama::Activity | |
activity :follow_user do | |
actor :user, :cache => [:name] | |
target :user, :cache => [:name] | |
end | |
activity :follow_event do | |
actor :user, :cache => [:name] | |
target :event, :cache => [:name] | |
end | |
end | |
class User | |
include Mongoid::Document | |
include Streama::Actor | |
field :name, :type => String | |
def followers | |
User.excludes(:id => self.id).all | |
end | |
end | |
class Event | |
include Mongoid::Document | |
include Streama::Actor | |
field :name, :type => String | |
def followers | |
User.all | |
end | |
end |
This file contains 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
ruby-1.9.2-p0 > u = User.first | |
=> #<User _id: 4df0e0b0ba3aad09f9000002, _type: nil, name: "jmaicher"> | |
ruby-1.9.2-p0 > e = Event.first | |
=> #<Event _id: 4df0e0a6ba3aad09f9000001, _type: nil, name: "ECTEL 2011"> | |
ruby-1.9.2-p0 > u.publish_activity(:follow_event, :target => e) | |
=> #<Activity _id: 4df0e21cba3aad0a83000005, _type: nil, created_at: 2011-06-09 15:09:16 UTC, updated_at: 2011-06-09 15:09:16 UTC, name: :follow_event, actor: {"id"=>BSON::ObjectId('4df0e0b0ba3aad09f9000002'), "type"=>"User", "name"=>"jmaicher"}, target: {"id"=>BSON::ObjectId('4df0e0a6ba3aad09f9000001'), "type"=>"Event", "name"=>"ECTEL 2011"}, referrer: nil, receivers: [{:id=>BSON::ObjectId('4df0e211ba3aad0a83000003'), :type=>"User"}, {:id=>BSON::ObjectId('4df0e219ba3aad0a83000004'), :type=>"User"}]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment