mongoid_followable 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/.idea/misc.xml CHANGED
@@ -3,6 +3,6 @@
3
3
  <component name="DependencyValidationManager">
4
4
  <option name="SKIP_IMPORT_STATEMENTS" value="false" />
5
5
  </component>
6
- <component name="ProjectRootManager" version="2" project-jdk-name="RVM: ruby-1.9.2-p136" project-jdk-type="RUBY_SDK" />
6
+ <component name="ProjectRootManager" version="2" project-jdk-name="ruby-1.9.2-p0" project-jdk-type="RUBY_SDK" />
7
7
  </project>
8
8
 
data/.idea/workspace.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <project version="4">
3
3
  <component name="ChangeListManager">
4
4
  <list default="true" id="90bdec60-890b-4083-b05d-2f665a1f4d70" name="Default" comment="">
5
- <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/mongoid_followable.iml" afterPath="$PROJECT_DIR$/.idea/mongoid_followable.iml" />
5
+ <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/misc.xml" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
6
6
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
7
7
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.rdoc" afterPath="$PROJECT_DIR$/README.rdoc" />
8
8
  <change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/mongoid_followable/followable.rb" afterPath="$PROJECT_DIR$/lib/mongoid_followable/followable.rb" />
@@ -48,7 +48,6 @@
48
48
  <list>
49
49
  <option value="$PROJECT_DIR$/app/models/followee.rb" />
50
50
  <option value="$PROJECT_DIR$/app/models/follower.rb" />
51
- <option value="$PROJECT_DIR$/spec/models/group.rb" />
52
51
  <option value="$PROJECT_DIR$/lib/mongoid_followable/follow.rb" />
53
52
  <option value="$PROJECT_DIR$/lib/generators/mongoid_followable/install_generator.rb" />
54
53
  <option value="$PROJECT_DIR$/spec/spec_helper.rb" />
@@ -57,9 +56,10 @@
57
56
  <option value="$PROJECT_DIR$/spec/models/user.rb" />
58
57
  <option value="$PROJECT_DIR$/lib/mongoid_followable/version.rb" />
59
58
  <option value="$PROJECT_DIR$/mongoid_followable.gemspec" />
59
+ <option value="$PROJECT_DIR$/spec/models/group.rb" />
60
60
  <option value="$PROJECT_DIR$/spec/mongoid/followable_spec.rb" />
61
- <option value="$PROJECT_DIR$/lib/mongoid_followable/follower.rb" />
62
61
  <option value="$PROJECT_DIR$/lib/mongoid_followable/followable.rb" />
62
+ <option value="$PROJECT_DIR$/lib/mongoid_followable/follower.rb" />
63
63
  <option value="$PROJECT_DIR$/README.rdoc" />
64
64
  </list>
65
65
  </option>
@@ -90,6 +90,7 @@
90
90
  <sortByType />
91
91
  </navigator>
92
92
  <panes>
93
+ <pane id="Favorites" />
93
94
  <pane id="ProjectPane">
94
95
  <subPane>
95
96
  <PATH>
@@ -118,7 +119,7 @@
118
119
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
119
120
  </PATH_ELEMENT>
120
121
  <PATH_ELEMENT>
121
- <option name="myItemId" value="spec" />
122
+ <option name="myItemId" value="lib" />
122
123
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
123
124
  </PATH_ELEMENT>
124
125
  </PATH>
@@ -132,31 +133,13 @@
132
133
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
133
134
  </PATH_ELEMENT>
134
135
  <PATH_ELEMENT>
135
- <option name="myItemId" value="spec" />
136
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
137
- </PATH_ELEMENT>
138
- <PATH_ELEMENT>
139
- <option name="myItemId" value="mongoid" />
136
+ <option name="myItemId" value="lib" />
140
137
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
141
138
  </PATH_ELEMENT>
142
- </PATH>
143
- <PATH>
144
- <PATH_ELEMENT>
145
- <option name="myItemId" value="mongoid_followable" />
146
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
147
- </PATH_ELEMENT>
148
139
  <PATH_ELEMENT>
149
140
  <option name="myItemId" value="mongoid_followable" />
150
141
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
151
142
  </PATH_ELEMENT>
152
- <PATH_ELEMENT>
153
- <option name="myItemId" value="spec" />
154
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
155
- </PATH_ELEMENT>
156
- <PATH_ELEMENT>
157
- <option name="myItemId" value="models" />
158
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
159
- </PATH_ELEMENT>
160
143
  </PATH>
161
144
  <PATH>
162
145
  <PATH_ELEMENT>
@@ -168,32 +151,17 @@
168
151
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
169
152
  </PATH_ELEMENT>
170
153
  <PATH_ELEMENT>
171
- <option name="myItemId" value="lib" />
172
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
173
- </PATH_ELEMENT>
174
- </PATH>
175
- <PATH>
176
- <PATH_ELEMENT>
177
- <option name="myItemId" value="mongoid_followable" />
178
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
179
- </PATH_ELEMENT>
180
- <PATH_ELEMENT>
181
- <option name="myItemId" value="mongoid_followable" />
154
+ <option name="myItemId" value="app" />
182
155
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
183
156
  </PATH_ELEMENT>
184
157
  <PATH_ELEMENT>
185
- <option name="myItemId" value="lib" />
186
- <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
187
- </PATH_ELEMENT>
188
- <PATH_ELEMENT>
189
- <option name="myItemId" value="mongoid_followable" />
158
+ <option name="myItemId" value="models" />
190
159
  <option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
191
160
  </PATH_ELEMENT>
192
161
  </PATH>
193
162
  </subPane>
194
163
  </pane>
195
164
  <pane id="Scope" />
196
- <pane id="Favorites" />
197
165
  </panes>
198
166
  </component>
199
167
  <component name="RecentsManager">
@@ -248,14 +216,14 @@
248
216
  <servers />
249
217
  </component>
250
218
  <component name="ToolWindowManager">
251
- <frame x="1" y="24" width="1598" height="851" extended-state="0" />
219
+ <frame x="0" y="24" width="1280" height="752" extended-state="4" />
252
220
  <editor active="false" />
253
221
  <layout>
254
222
  <window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
255
223
  <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
256
224
  <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
257
225
  <window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
258
- <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.17579618" sideWeight="0.67128986" order="0" side_tool="false" content_ui="tabs" />
226
+ <window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.1754386" sideWeight="0.67128986" order="0" side_tool="false" content_ui="tabs" />
259
227
  <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
260
228
  <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
261
229
  <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
@@ -306,11 +274,6 @@
306
274
  <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
307
275
  </provider>
308
276
  </entry>
309
- <entry file="file://$PROJECT_DIR$/Gemfile">
310
- <provider selected="true" editor-type-id="text-editor">
311
- <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
312
- </provider>
313
- </entry>
314
277
  <entry file="file://$PROJECT_DIR$/LICENSE.txt">
315
278
  <provider selected="true" editor-type-id="text-editor">
316
279
  <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
@@ -321,68 +284,73 @@
321
284
  <state line="10" column="44" selection-start="315" selection-end="315" vertical-scroll-proportion="0.2173913" />
322
285
  </provider>
323
286
  </entry>
324
- <entry file="file://$PROJECT_DIR$/spec/spec_helper.rb">
287
+ <entry file="file://$PROJECT_DIR$/lib/mongoid_followable.rb">
288
+ <provider selected="true" editor-type-id="text-editor">
289
+ <state line="1" column="70" selection-start="145" selection-end="145" vertical-scroll-proportion="0.0" />
290
+ </provider>
291
+ </entry>
292
+ <entry file="file://$PROJECT_DIR$/Gemfile">
325
293
  <provider selected="true" editor-type-id="text-editor">
326
294
  <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
327
295
  </provider>
328
296
  </entry>
329
297
  <entry file="file://$PROJECT_DIR$/mongoid_followable.gemspec">
330
298
  <provider selected="true" editor-type-id="text-editor">
331
- <state line="8" column="29" selection-start="292" selection-end="292" vertical-scroll-proportion="0.17391305">
299
+ <state line="8" column="29" selection-start="292" selection-end="292" vertical-scroll-proportion="0.20236088">
332
300
  <folding />
333
301
  </state>
334
302
  </provider>
335
303
  </entry>
336
304
  <entry file="file://$PROJECT_DIR$/lib/mongoid_followable/version.rb">
337
305
  <provider selected="true" editor-type-id="text-editor">
338
- <state line="2" column="20" selection-start="55" selection-end="55" vertical-scroll-proportion="0.04347826">
306
+ <state line="2" column="20" selection-start="55" selection-end="55" vertical-scroll-proportion="0.05059022">
339
307
  <folding />
340
308
  </state>
341
309
  </provider>
342
310
  </entry>
343
- <entry file="file://$PROJECT_DIR$/lib/mongoid_followable.rb">
311
+ <entry file="file://$PROJECT_DIR$/spec/spec_helper.rb">
344
312
  <provider selected="true" editor-type-id="text-editor">
345
- <state line="1" column="70" selection-start="145" selection-end="145" vertical-scroll-proportion="0.0" />
313
+ <state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
346
314
  </provider>
347
315
  </entry>
348
- <entry file="file://$PROJECT_DIR$/spec/models/user.rb">
316
+ <entry file="file://$PROJECT_DIR$/spec/models/group.rb">
349
317
  <provider selected="true" editor-type-id="text-editor">
350
- <state line="3" column="27" selection-start="96" selection-end="96" vertical-scroll-proportion="0.0">
318
+ <state line="2" column="29" selection-start="69" selection-end="69" vertical-scroll-proportion="0.05059022">
351
319
  <folding />
352
320
  </state>
353
321
  </provider>
354
322
  </entry>
355
- <entry file="file://$PROJECT_DIR$/README.rdoc">
323
+ <entry file="file://$PROJECT_DIR$/spec/models/user.rb">
356
324
  <provider selected="true" editor-type-id="text-editor">
357
- <state line="7" column="37" selection-start="136" selection-end="136" vertical-scroll-proportion="0.1521739">
325
+ <state line="3" column="27" selection-start="96" selection-end="96" vertical-scroll-proportion="0.075885326">
358
326
  <folding />
359
327
  </state>
360
328
  </provider>
361
329
  </entry>
362
- <entry file="file://$PROJECT_DIR$/lib/mongoid_followable/followable.rb">
330
+ <entry file="file://$PROJECT_DIR$/README.rdoc">
363
331
  <provider selected="true" editor-type-id="text-editor">
364
- <state line="37" column="19" selection-start="1000" selection-end="1000" vertical-scroll-proportion="0.41304347">
332
+ <state line="100" column="39" selection-start="2833" selection-end="2833" vertical-scroll-proportion="2.586207">
365
333
  <folding />
366
334
  </state>
367
335
  </provider>
368
336
  </entry>
369
337
  <entry file="file://$PROJECT_DIR$/lib/mongoid_followable/follower.rb">
370
338
  <provider selected="true" editor-type-id="text-editor">
371
- <state line="37" column="22" selection-start="991" selection-end="991" vertical-scroll-proportion="0.37518463">
339
+ <state line="184" column="81" selection-start="5237" selection-end="5237" vertical-scroll-proportion="0.4051724">
372
340
  <folding />
373
341
  </state>
374
342
  </provider>
375
343
  </entry>
376
- <entry file="file://$PROJECT_DIR$/spec/mongoid/followable_spec.rb">
344
+ <entry file="file://$PROJECT_DIR$/lib/mongoid_followable/followable.rb">
377
345
  <provider selected="true" editor-type-id="text-editor">
378
- <state line="92" column="19" selection-start="2370" selection-end="2370" vertical-scroll-proportion="1.7826087">
346
+ <state line="166" column="16" selection-start="4352" selection-end="4352" vertical-scroll-proportion="0.59527826">
379
347
  <folding />
380
348
  </state>
381
349
  </provider>
382
350
  </entry>
383
- <entry file="file://$PROJECT_DIR$/spec/models/group.rb">
351
+ <entry file="file://$PROJECT_DIR$/spec/mongoid/followable_spec.rb">
384
352
  <provider selected="true" editor-type-id="text-editor">
385
- <state line="2" column="29" selection-start="69" selection-end="69" vertical-scroll-proportion="0.04347826">
353
+ <state line="81" column="21" selection-start="2066" selection-end="2066" vertical-scroll-proportion="0.02529511">
386
354
  <folding />
387
355
  </state>
388
356
  </provider>
data/README.rdoc CHANGED
@@ -78,6 +78,16 @@ Another feature is to get a list of models which has the most followers/followee
78
78
  Group.with_min_followers
79
79
  Group.with_max_followers_by_type('user')
80
80
  Group.with_min_followers_by_type('user')
81
+
82
+ Now you can tell if two models have some common followers/followees by following methods:
83
+
84
+ @user.common_followees?(@another_user)
85
+ @user.common_followers?(@group)
86
+
87
+ And see what the common followers/followees are:
88
+
89
+ @user.common_followees_with(@another_user)
90
+ @user.common_followers_with(@group)
81
91
 
82
92
  * Any bug or issue, please send me an email: ustc.flyingfox@gmail.com
83
93
 
@@ -88,7 +98,7 @@ Another feature is to get a list of models which has the most followers/followee
88
98
  * following history/followed history #FINISHED#
89
99
  * most/least followed/following #FINISHED
90
100
  * add authorization to followable models #FINISHED#
91
- * follow part of model like only following tags updation of an article etc(is this necessary?)
101
+ * common followers/followees #FINISHED#
92
102
 
93
103
  == Thanks
94
104
 
@@ -147,6 +147,26 @@ module Mongoid
147
147
  follow
148
148
  end
149
149
 
150
+ # return if there is any common followers
151
+ #
152
+ # Example:
153
+ # >> @ruby.common_followees?(@python)
154
+ # => true
155
+
156
+ def common_followers?(model)
157
+ 0 < (rebuild_instances(self.followers) & rebuild_instances(model.followers)).length
158
+ end
159
+
160
+ # get common followers with some model
161
+ #
162
+ # Example:
163
+ # >> @ruby.common_followers_with(@python)
164
+ # => [@jim]
165
+
166
+ def common_followers_with(model)
167
+ rebuild_instances(self.followers) & rebuild_instances(model.followers)
168
+ end
169
+
150
170
  private
151
171
  def rebuild_instances(follows)
152
172
  follow_list = []
@@ -175,6 +175,26 @@ module Mongoid
175
175
  follow
176
176
  end
177
177
 
178
+ # return if there is any common followees
179
+ #
180
+ # Example:
181
+ # >> @jim.common_followees?(@tom)
182
+ # => true
183
+
184
+ def common_followees?(model)
185
+ 0 < (rebuild_instances(self.followees) & rebuild_instances(model.followees)).length
186
+ end
187
+
188
+ # get common followees with some model
189
+ #
190
+ # Example:
191
+ # >> @jim.common_followees_with(@tom)
192
+ # => [@ruby]
193
+
194
+ def common_followees_with(model)
195
+ rebuild_instances(self.followees) & rebuild_instances(model.followees)
196
+ end
197
+
178
198
  private
179
199
  def rebuild_instances(follows)
180
200
  follow_list = []
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Followable
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.8"
4
4
  end
5
5
  end
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
6
6
  s.name = "mongoid_followable"
7
7
  s.version = Mongoid::Followable::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.date = "2011-06-29"
9
+ s.date = "2011-07-04"
10
10
  s.authors = ["Jie Fan"]
11
11
  s.email = ["ustc.flyingfox@gmail.com"]
12
12
  s.homepage = "https://github.com/lastomato/mongoid_followable"
@@ -39,6 +39,11 @@ describe Mongoid::Followable do
39
39
  u.ever_follow.should == [@v]
40
40
  @v.ever_followed.should == [u]
41
41
 
42
+ u.common_followees?(@v).should be_false
43
+ @v.common_followers?(u).should be_false
44
+ u.common_followees_with(@v).should == []
45
+ @v.common_followers_with(u).should == []
46
+
42
47
  User.with_max_followees.should == [u]
43
48
  User.with_max_followers.should == [@v]
44
49
  User.with_max_followees_by_type('user').should == [u]
@@ -87,6 +92,11 @@ describe Mongoid::Followable do
87
92
  u.ever_follow.should == [@g, @v]
88
93
  @g.ever_followed.should == [u]
89
94
 
95
+ u.common_followees?(@v).should be_false
96
+ @v.common_followers?(@g).should be_true
97
+ u.common_followees_with(@v).should == []
98
+ @v.common_followers_with(@g).should == [u]
99
+
90
100
  User.with_max_followees.should == [u]
91
101
  Group.with_max_followers.should == [@g]
92
102
  User.with_max_followees_by_type('group').should == [u]
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_followable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
4
  prerelease:
6
- segments:
7
- - 0
8
- - 1
9
- - 6
10
- version: 0.1.6
5
+ version: 0.1.8
11
6
  platform: ruby
12
7
  authors:
13
8
  - Jie Fan
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-29 00:00:00 -04:00
13
+ date: 2011-07-04 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 2
32
- - 0
33
- - 1
34
24
  version: 2.0.1
35
25
  type: :runtime
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ~>
44
34
  - !ruby/object:Gem::Version
45
- hash: 27
46
- segments:
47
- - 1
48
- - 3
49
- - 0
50
35
  version: 1.3.0
51
36
  type: :runtime
52
37
  version_requirements: *id002
@@ -58,10 +43,6 @@ dependencies:
58
43
  requirements:
59
44
  - - ~>
60
45
  - !ruby/object:Gem::Version
61
- hash: 7
62
- segments:
63
- - 0
64
- - 6
65
46
  version: "0.6"
66
47
  type: :development
67
48
  version_requirements: *id003
@@ -73,10 +54,6 @@ dependencies:
73
54
  requirements:
74
55
  - - ~>
75
56
  - !ruby/object:Gem::Version
76
- hash: 15
77
- segments:
78
- - 2
79
- - 6
80
57
  version: "2.6"
81
58
  type: :development
82
59
  version_requirements: *id004
@@ -128,23 +105,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
128
105
  requirements:
129
106
  - - ">="
130
107
  - !ruby/object:Gem::Version
131
- hash: 3
132
- segments:
133
- - 0
134
108
  version: "0"
135
109
  required_rubygems_version: !ruby/object:Gem::Requirement
136
110
  none: false
137
111
  requirements:
138
112
  - - ">="
139
113
  - !ruby/object:Gem::Version
140
- hash: 3
141
- segments:
142
- - 0
143
114
  version: "0"
144
115
  requirements: []
145
116
 
146
117
  rubyforge_project: mongoid_followable
147
- rubygems_version: 1.4.1
118
+ rubygems_version: 1.6.2
148
119
  signing_key:
149
120
  specification_version: 3
150
121
  summary: adds following feature to models