Skip to content

Commit

Permalink
Version 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
felixclack committed Feb 27, 2012
1 parent e75a654 commit 5feb395
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Gemfile.lock
@@ -1,7 +1,8 @@
PATH
remote: .
specs:
timeline (0.0.2)
timeline (0.1.1)
activemodel (~> 3.2)
activesupport (~> 3.2)
hashie
multi_json
Expand All @@ -10,9 +11,13 @@ PATH
GEM
remote: http://rubygems.org/
specs:
activemodel (3.2.1)
activesupport (= 3.2.1)
builder (~> 3.0.0)
activesupport (3.2.1)
i18n (~> 0.6)
multi_json (~> 1.0)
builder (3.0.0)
hashie (1.2.0)
i18n (0.6.0)
multi_json (1.1.0)
Expand Down
17 changes: 15 additions & 2 deletions History.txt
@@ -1,4 +1,17 @@
== 0.1.3 / 2012-02-28

* Accept :extra_fields as an option for track, to cache extra fields on the timeline post.

== 0.1.2 / 2012-02-25

* Add ActiveModel::Naming to Timeline::Activity so that it can be passed to the render method in Rails.


== 0.1.1 / 2012-02-24

* Add json-ified object to lists.


== 0.1.0 / 2012-02-17

* 1 major enhancement
* Birthday!
* First commit
7 changes: 7 additions & 0 deletions lib/timeline/activity.rb
@@ -1,4 +1,11 @@
require 'active_model'

module Timeline
class Activity < Hashie::Mash
extend ActiveModel::Naming

def to_partial_path
"timelines/#{verb}"
end
end
end
28 changes: 22 additions & 6 deletions lib/timeline/track.rb
Expand Up @@ -12,10 +12,10 @@ def track(name, options={})
@target = options.delete :target
@followers = options.delete :followers
@followers ||= :followers

@extra_fields = options.delete :extra_fields

method_name = "track_#{@name}_after_#{@callback}".to_sym
define_activity_method method_name, actor: @actor, object: @object, target: @target, followers: @followers, verb: name
define_activity_method method_name, actor: @actor, object: @object, target: @target, followers: @followers, verb: name, extra_fields: @extra_fields

send "after_#{@callback}".to_sym, method_name, if: options.delete(:if)
end
Expand All @@ -27,7 +27,7 @@ def define_activity_method(method_name, options={})
object = !options[:object].nil? ? send(options[:object].to_sym) : self
target = !options[:target].nil? ? send(options[:target].to_sym) : nil
followers = actor.send(options[:followers].to_sym)
add_activity activity(verb: options[:verb], actor: actor, object: object, target: target), followers
add_activity activity(verb: options[:verb], actor: actor, object: object, target: target, extra_fields: options[:extra_fields]), followers
end
end
end
Expand All @@ -38,24 +38,40 @@ def activity(options={})
verb: options[:verb],
actor: options_for(options[:actor]),
object: options_for(options[:object]),
target: options_for(options[:target])
}
target: options_for(options[:target]),
created_at: Time.now
}.merge(add_extra_fields(options[:extra_fields]))
end

def add_activity(activity_item, followers)
redis_add "global:activity", activity_item
add_activity_to_user(activity_item, activity_item[:actor][:actor_id])
add_activity_to_user(activity_item, activity_item[:actor][:id])
add_activity_to_user_post(activity_item, activity_item[:actor][:id])
add_activity_to_followers(activity_item, followers) if followers.any?
end

def add_activity_to_user(activity_item, user_id)
redis_add "user:id:#{user_id}:activity", activity_item
end

def add_activity_to_user_post(activity_item, user_id)
redis_add "user:id:#{user_id}:posts", activity_item
end

def add_activity_to_followers(activity_item, followers)
followers.each { |follower| add_activity_to_user(activity_item, follower.id) }
end

def add_extra_fields(extra_fields)
if extra_fields.any?
extra_fields.inject({}) do |sum, value|
sum = send value.to_sym
end
else
{}
end
end

def redis_add(list, activity_item)
Timeline.redis.lpush list, Timeline.encode(activity_item)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/timeline/version.rb
@@ -1,3 +1,3 @@
module Timeline
VERSION = "0.1.0"
VERSION = "0.1.3"
end
1 change: 1 addition & 0 deletions timeline.gemspec
Expand Up @@ -17,6 +17,7 @@ Gem::Specification.new do |s|
s.test_files = Dir["test/**/*"]

s.add_dependency "activesupport", "~>3.2"
s.add_dependency "activemodel", "~>3.2"
s.add_dependency "multi_json"
s.add_dependency "redis"
s.add_dependency "hashie"
Expand Down

0 comments on commit 5feb395

Please sign in to comment.