Skip to content
This repository has been archived by the owner on Jun 5, 2020. It is now read-only.

Commit

Permalink
Version bump to 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
christospappas committed May 31, 2011
1 parent 1e4887a commit 5f2acac
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 269 deletions.
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,8 +1,8 @@
source "http://rubygems.org"

gem "activesupport", "~> 3.0"
gem "mongoid", "~> 2.0.0.rc"
gem "bson_ext", "~> 1.2"
gem "will_paginate", "~> 3.0.pre2"

group :development do
gem "rspec", "~> 2.3.0"
Expand Down
28 changes: 13 additions & 15 deletions Gemfile.lock
@@ -1,13 +1,13 @@
GEM
remote: http://rubygems.org/
specs:
activemodel (3.0.4)
activesupport (= 3.0.4)
activemodel (3.0.7)
activesupport (= 3.0.7)
builder (~> 2.1.2)
i18n (~> 0.4)
activesupport (3.0.4)
bson (1.2.1)
bson_ext (1.2.1)
i18n (~> 0.5.0)
activesupport (3.0.7)
bson (1.3.1)
bson_ext (1.3.1)
builder (2.1.2)
diff-lcs (1.1.2)
git (1.2.5)
Expand All @@ -16,14 +16,13 @@ GEM
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
mongo (1.2.1)
bson (>= 1.2.1)
mongoid (2.0.0.rc.7)
mongo (1.3.1)
bson (>= 1.3.1)
mongoid (2.0.2)
activemodel (~> 3.0)
mongo (~> 1.2)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
will_paginate (~> 3.0.pre)
rake (0.8.7)
rake (0.9.0)
rcov (0.9.9)
rspec (2.3.0)
rspec-core (~> 2.3.0)
Expand All @@ -33,17 +32,16 @@ GEM
rspec-expectations (2.3.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.3.0)
tzinfo (0.3.24)
will_paginate (3.0.pre2)
tzinfo (0.3.27)

PLATFORMS
ruby

DEPENDENCIES
activesupport (~> 3.0)
bson_ext (~> 1.2)
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
mongoid (~> 2.0.0.rc)
rcov
rspec (~> 2.3.0)
will_paginate (~> 3.0.pre2)
66 changes: 16 additions & 50 deletions README.rdoc
Expand Up @@ -10,14 +10,18 @@ Streama is a simple Ruby activity stream gem for use with the Mongoid ODM framew

=== Define Activities

In an initializer define the activities and the fields you would like to store within the activity.
Create an Activity model and define the activities and the fields you would like to cache within the activity.

Streama::Activity.define(:enquiry) do
actor :user, :store => [:full_name]
target :enquiry, :store => [:subject]
referrer :listing, :store => [:title]
class Activity
include Streama::Activity

activity :enquiry do
actor :user, :cache => [:full_name]
target :enquiry, :cache => [:subject]
referrer :listing, :cache => [:title]
end


end

=== Setup Actors

Expand All @@ -32,50 +36,23 @@ Include the Actor module in a class and override the default followers method.
end
end

You can define multiple activity streams to publish to in your Actor.

The :followers parameter defines the method which returns recipients of the activity.

class User
include Mongoid::Document
include Streama::Actor

activity_stream(:friends, :followers => :friends)
activity_stream(:family, :followers => :family)

def friends
...
end

def family
...
end

end

If you like you can also override the default activity stream follower method

activity_stream(:default, :followers => :your_method)

=== Setup Indexes

You need to manually create the indexes for both the Activity and Stream collections. You can do so by calling the create_indexes method.

Streama::Activity.create_indexes
Streama::Stream.create_indexes
Create the indexes for the Activities collection. You can do so by calling the create_indexes method.

Activity.create_indexes

=== Publishing Activity

In your controller or background worker:

current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing)

This will send to to the :default stream.
This will publish the activity to the objects returned by the "followers" method in the Actor.

To send your activity to a different stream defined in your actor or a collection of receivers, pass in an additional :receivers parameter.
To send your activity to different receievers, pass in an additional :receivers parameter.

current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing, :receivers => :friends)
current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing, :receivers => :friends) # calls friends method
current_user.publish_activity(:enquiry, :target => @enquiry, :referrer => @listing, :receivers => current_user.find(:all, :conditions => {:group_id => mygroup}))

== Retrieving Activity
Expand All @@ -87,16 +64,12 @@ To retrieve all activity for an actor
To retrieve and filter to a particular activity type

current_user.activity_stream(:type => :activity_type)

You can paginate your results as well

current_user.activity_stream(:page => 1, :per_page => 10)

If you need to return the instance of an :actor, :target or :referrer from an activity call the Activity#load_instance method

activity.load_instance(:actor)

You can also refresh the stored activity data by calling the Activity#refresh_data method
You can also refresh the cached activity data by calling the Activity#refresh_data method

activity.refresh_data

Expand All @@ -106,17 +79,10 @@ Streama is developed against Ruby 1.9.2 and Mongoid 2.0.0.rc7

== TODO

* Create a module that listens for changes to targets, referrer objects and updates activity metadata.
* Write more documentation, YARD
* Write more tests
* Benchmarks

== Notes

* I haven't tested this in production yet. I still need to validate whether the way this gem works is ok.
* Streama inserts an association record for every recipient of an activity. MongoDB handles thousands of inserts within milliseconds, so it should be able to handle most cases. If storage size is a problem consider using capped collections (Need to test this with mongoid). I'm looking into whether embedding the relation within the actor object is better.
* If you are looking for something that works with ActiveRecord take a look at fullsailors' {activity_stream}[https://github.com/fullsailor/activity_stream] which inspired this gem.

= License

Copyright © 2011 Christos Pappas
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.1.5
0.2.0
1 change: 0 additions & 1 deletion lib/streama.rb
@@ -1,5 +1,4 @@
require 'mongoid'
require 'streama/stream'
require 'streama/actor'
require 'streama/activity'
require 'streama/definition'
Expand Down

0 comments on commit 5f2acac

Please sign in to comment.