acts_as_stream 0.0.3.alpha.1 → 0.0.3.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -99,7 +99,7 @@ Followers are notified by an arbitrary string key that can literally be whatever
99
99
  to
100
100
 
101
101
  ```
102
- <namespace>:<activity_scope>:<streamable_object_id> <time> <activity_id>
102
+ <namespace>:<class.name.tableize.singularize>:<streamable_object_id>:<activity_scope> <time> <activity_id>
103
103
  ```
104
104
 
105
105
  where ```streamable_object_id``` is the value of ```activity_attr```, both of which are set in the configuration options.
@@ -116,6 +116,23 @@ where ```follower_key``` is the key used above, and activity_id is the id of the
116
116
 
117
117
  The following system allows for time sorted organization of activities, and ability to see all "viewers" of an activity.
118
118
 
119
+ ### Mentions
120
+
121
+ Unless ```:ignore_mentions``` is provided to the acts_as_stream method, mentioned objects can be notified if they were "discussed" in activity. The key
122
+ pattern for this is
123
+
124
+ ```
125
+ <namespace>:<class.name.tableize.singularize>:<streamable_object_id>:<mentions_scope> <time> <activity_id>
126
+ ```
127
+
128
+ and the list by id is
129
+ ```
130
+ <namespace>:<activity_scope>:<mentions_key>:<activity_id> <mentioned_key>
131
+ ```
132
+
133
+ The attribute ```mentions_scope``` is provided in the ActsAsStream configuration and defaults to ```:mentions```. This can
134
+ be overwritten by sending :mentions_scope as an attribute to acts_as_stream.
135
+
119
136
  ## Configuration
120
137
 
121
138
  ## Future Plans
@@ -9,7 +9,8 @@ module ActsAsStream
9
9
  :activity_scope,
10
10
  :activity_attr,
11
11
  :page_size,
12
- :activity_incr
12
+ :activity_incr,
13
+ :mentions_scope
13
14
 
14
15
  def configure
15
16
  yield self
@@ -45,5 +46,9 @@ module ActsAsStream
45
46
  @activity_incr
46
47
  end
47
48
 
49
+ def mentions_scope
50
+ @mentions_scope ||= :mentions
51
+ end
52
+
48
53
  end
49
54
  end
@@ -20,6 +20,7 @@ module ActsAsStream
20
20
  ActsAsStream.redis.zrem "#{base_key}:sorted", ident
21
21
  end
22
22
  deregister_followers! ident
23
+ deregister_mentioned! ident
23
24
  end
24
25
 
25
26
  def register_followers! options = {}
@@ -48,6 +49,33 @@ module ActsAsStream
48
49
  end
49
50
  end
50
51
 
52
+ def register_mentions! options = {}
53
+ options.assert_valid_keys(:mentioned_keys, :activity_id)
54
+ return if options[:mentioned_keys].nil? or options[:activity_id].nil?
55
+ raise ":mentioned_keys must be an array of keys" if not options[:mentioned_keys].is_a? Array
56
+ ActsAsStream.redis.multi do
57
+ options[:mentioned_keys].each do |key|
58
+ ActsAsStream.redis.zadd key, Time.now.to_f, options[:activity_id]
59
+ ActsAsStream.redis.lpush "#{base_key}:mentions:#{options[:activity_id]}", key
60
+ end
61
+ end
62
+ end
63
+
64
+ def deregister_mentioned! activity_id = nil
65
+ return if activity_id.nil?
66
+ mentioned_key = "#{base_key}:mentions:#{activity_id}"
67
+ return if mentioned_key.nil?
68
+ len = ActsAsStream.redis.llen mentioned_key
69
+ mentioned = ActsAsStream.redis.lrange mentioned_key, 0, len
70
+ return if mentioned.nil?
71
+ ActsAsStream.redis.multi do
72
+ mentioned.each do |f|
73
+ ActsAsStream.redis.zrem f, activity_id
74
+ end
75
+ ActsAsStream.redis.del "#{base_key}:mentions:#{activity_id}"
76
+ end
77
+ end
78
+
51
79
  def get_activity_for follower_key, options = {}
52
80
  options = {:page => 1, :page_size => ActsAsStream.page_size}.merge options
53
81
  options[:page] = 1 if options[:page] < 1
@@ -8,12 +8,16 @@ module ActsAsStream
8
8
  module ClassMethods
9
9
 
10
10
  def acts_as_stream options = {}
11
- cattr_accessor :activity_scope, :activity_attr, :activity_key_base, :followers_attr
11
+ cattr_accessor :activity_scope, :activity_attr, :activity_key_base, :followers_attr, :mentions_scope
12
12
  self.activity_scope = options[:activity_scope] || ActsAsStream.activity_scope
13
+ self.mentions_scope = options[:mentions_scope] || ActsAsStream.mentions_scope
13
14
  self.activity_attr = options[:activity_attr] || ActsAsStream.activity_attr
14
15
  self.activity_key_base = "#{ActsAsStream.namespace}:#{self.activity_scope}"
15
16
  self.followers_attr = options[:followers_attr] || :all_followers
16
17
  send :include, ActsAsStream::StreamableObject::InstanceMethods
18
+ unless options[:ignore_mentions]
19
+ send :include, ActsAsStream::StreamableObject::MentionsMethods
20
+ end
17
21
  end
18
22
  end
19
23
 
@@ -31,10 +35,10 @@ module ActsAsStream
31
35
  def following_key
32
36
  "#{ActsAsStream.namespace}:#{self.class.name.tableize.singularize}:#{streamable_object_id}:#{activity_scope}"
33
37
  end
34
-
35
38
  def register_activity! package
36
39
  act_id = ActsAsStream.register_new_activity! package
37
40
  self.register_followers! act_id
41
+ act_id
38
42
  end
39
43
 
40
44
  def delete_activity act_id
@@ -75,5 +79,15 @@ module ActsAsStream
75
79
  end
76
80
 
77
81
  end
82
+
83
+ module MentionsMethods
84
+ def register_mentions!(options = {})
85
+ options[:mentioned_keys] = [options[:mentioned_keys]] unless options[:mentioned_keys].is_a?(Array)
86
+ ActsAsStream.register_mentions! :mentioned_keys => options[:mentioned_keys], :activity_id => options[:activity_id]
87
+ end
88
+ def mentions_key
89
+ "#{ActsAsStream.namespace}:#{self.class.name.tableize.singularize}:#{streamable_object_id}:#{mentions_scope}"
90
+ end
91
+ end
78
92
  end
79
93
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsStream
2
- VERSION = "0.0.3.alpha.1"
2
+ VERSION = "0.0.3.alpha.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3.alpha.1
4
+ version: 0.0.3.alpha.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70294530388220 !ruby/object:Gem::Requirement
16
+ requirement: &70342865651640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70294530388220
24
+ version_requirements: *70342865651640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: redis
27
- requirement: &70294530387540 !ruby/object:Gem::Requirement
27
+ requirement: &70342865651060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70294530387540
35
+ version_requirements: *70342865651060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70294530386780 !ruby/object:Gem::Requirement
38
+ requirement: &70342865650140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70294530386780
46
+ version_requirements: *70342865650140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: acts_as_amico
49
- requirement: &70294530385860 !ruby/object:Gem::Requirement
49
+ requirement: &70342865649360 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70294530385860
57
+ version_requirements: *70342865649360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec-rails
60
- requirement: &70294530385100 !ruby/object:Gem::Requirement
60
+ requirement: &70342865648560 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70294530385100
68
+ version_requirements: *70342865648560
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: spork
71
- requirement: &70294530400080 !ruby/object:Gem::Requirement
71
+ requirement: &70342865663040 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.0.rc
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70294530400080
79
+ version_requirements: *70342865663040
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-rspec
82
- requirement: &70294530399320 !ruby/object:Gem::Requirement
82
+ requirement: &70342865662280 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70294530399320
90
+ version_requirements: *70342865662280
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: guard-spork
93
- requirement: &70294530398540 !ruby/object:Gem::Requirement
93
+ requirement: &70342865661640 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70294530398540
101
+ version_requirements: *70342865661640
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: factory_girl_rails
104
- requirement: &70294530397940 !ruby/object:Gem::Requirement
104
+ requirement: &70342865660340 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70294530397940
112
+ version_requirements: *70342865660340
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: simplecov
115
- requirement: &70294530396580 !ruby/object:Gem::Requirement
115
+ requirement: &70342865659380 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70294530396580
123
+ version_requirements: *70342865659380
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: fakeweb
126
- requirement: &70294530395540 !ruby/object:Gem::Requirement
126
+ requirement: &70342865658460 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70294530395540
134
+ version_requirements: *70342865658460
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: uuidtools
137
- requirement: &70294530394620 !ruby/object:Gem::Requirement
137
+ requirement: &70342865657200 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70294530394620
145
+ version_requirements: *70342865657200
146
146
  description: Rails injectable Redis-backed activity stream system. This is an alpha
147
147
  release of code that I just wrote and put into production on 3/11/12. Send feedback
148
148
  and post bugs to the Github page, but use at your own risk!