mongo_followable 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.idea/workspace.xml +90 -29
- data/README.rdoc +13 -1
- data/lib/mongo_followable/followable.rb +5 -1
- data/lib/mongo_followable/follower.rb +10 -2
- data/lib/mongo_followable/version.rb +1 -1
- data/spec/mongo/followable_spec.rb +34 -0
- metadata +3 -3
data/.idea/workspace.xml
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
<list default="true" id="46dc3a6d-3a97-49f8-becd-2ccba8c07e42" name="Default" comment="">
|
|
5
5
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
|
6
6
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/README.rdoc" afterPath="$PROJECT_DIR$/README.rdoc" />
|
|
7
|
+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/mongo_followable/followable.rb" afterPath="$PROJECT_DIR$/lib/mongo_followable/followable.rb" />
|
|
8
|
+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/mongo_followable/follower.rb" afterPath="$PROJECT_DIR$/lib/mongo_followable/follower.rb" />
|
|
7
9
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/lib/mongo_followable/version.rb" afterPath="$PROJECT_DIR$/lib/mongo_followable/version.rb" />
|
|
8
|
-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/mongo_followable.gemspec" afterPath="$PROJECT_DIR$/mongo_followable.gemspec" />
|
|
9
10
|
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/spec/mongo/followable_spec.rb" afterPath="$PROJECT_DIR$/spec/mongo/followable_spec.rb" />
|
|
10
|
-
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/spec/spec_helper.rb" afterPath="$PROJECT_DIR$/spec/spec_helper.rb" />
|
|
11
11
|
</list>
|
|
12
12
|
<ignored path="mongo_followable.iws" />
|
|
13
13
|
<ignored path=".idea/workspace.xml" />
|
|
@@ -31,10 +31,37 @@
|
|
|
31
31
|
</component>
|
|
32
32
|
<component name="FileEditorManager">
|
|
33
33
|
<leaf>
|
|
34
|
-
<file leaf-file-name="
|
|
35
|
-
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/
|
|
34
|
+
<file leaf-file-name="followable.rb" pinned="false" current="false" current-in-tab="false">
|
|
35
|
+
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/followable.rb">
|
|
36
36
|
<provider selected="true" editor-type-id="text-editor">
|
|
37
|
-
<state line="
|
|
37
|
+
<state line="127" column="36" selection-start="3865" selection-end="3865" vertical-scroll-proportion="0.0">
|
|
38
|
+
<folding />
|
|
39
|
+
</state>
|
|
40
|
+
</provider>
|
|
41
|
+
</entry>
|
|
42
|
+
</file>
|
|
43
|
+
<file leaf-file-name="README.rdoc" pinned="false" current="false" current-in-tab="false">
|
|
44
|
+
<entry file="file://$PROJECT_DIR$/README.rdoc">
|
|
45
|
+
<provider selected="true" editor-type-id="text-editor">
|
|
46
|
+
<state line="53" column="83" selection-start="1649" selection-end="1649" vertical-scroll-proportion="0.0">
|
|
47
|
+
<folding />
|
|
48
|
+
</state>
|
|
49
|
+
</provider>
|
|
50
|
+
</entry>
|
|
51
|
+
</file>
|
|
52
|
+
<file leaf-file-name="follower.rb" pinned="false" current="false" current-in-tab="false">
|
|
53
|
+
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/follower.rb">
|
|
54
|
+
<provider selected="true" editor-type-id="text-editor">
|
|
55
|
+
<state line="160" column="34" selection-start="4901" selection-end="4901" vertical-scroll-proportion="0.0">
|
|
56
|
+
<folding />
|
|
57
|
+
</state>
|
|
58
|
+
</provider>
|
|
59
|
+
</entry>
|
|
60
|
+
</file>
|
|
61
|
+
<file leaf-file-name="followable_spec.rb" pinned="false" current="true" current-in-tab="true">
|
|
62
|
+
<entry file="file://$PROJECT_DIR$/spec/mongo/followable_spec.rb">
|
|
63
|
+
<provider selected="true" editor-type-id="text-editor">
|
|
64
|
+
<state line="216" column="9" selection-start="4887" selection-end="4887" vertical-scroll-proportion="0.7826087">
|
|
38
65
|
<folding />
|
|
39
66
|
</state>
|
|
40
67
|
</provider>
|
|
@@ -60,13 +87,13 @@
|
|
|
60
87
|
<option value="$PROJECT_DIR$/spec/mongoid/group.rb" />
|
|
61
88
|
<option value="$PROJECT_DIR$/spec/mongoid/user.rb" />
|
|
62
89
|
<option value="$PROJECT_DIR$/lib/mongo_followable.rb" />
|
|
63
|
-
<option value="$PROJECT_DIR$/lib/mongo_followable/follower.rb" />
|
|
64
|
-
<option value="$PROJECT_DIR$/spec/mongo/followable_spec.rb" />
|
|
65
90
|
<option value="$PROJECT_DIR$/mongo_followable.gemspec" />
|
|
66
91
|
<option value="$PROJECT_DIR$/spec/spec_helper.rb" />
|
|
67
|
-
<option value="$PROJECT_DIR$/README.rdoc" />
|
|
68
|
-
<option value="$PROJECT_DIR$/lib/mongo_followable/followable.rb" />
|
|
69
92
|
<option value="$PROJECT_DIR$/lib/mongo_followable/version.rb" />
|
|
93
|
+
<option value="$PROJECT_DIR$/lib/mongo_followable/follower.rb" />
|
|
94
|
+
<option value="$PROJECT_DIR$/lib/mongo_followable/followable.rb" />
|
|
95
|
+
<option value="$PROJECT_DIR$/README.rdoc" />
|
|
96
|
+
<option value="$PROJECT_DIR$/spec/mongo/followable_spec.rb" />
|
|
70
97
|
</list>
|
|
71
98
|
</option>
|
|
72
99
|
</component>
|
|
@@ -96,7 +123,7 @@
|
|
|
96
123
|
<sortByType />
|
|
97
124
|
</navigator>
|
|
98
125
|
<panes>
|
|
99
|
-
<pane id="
|
|
126
|
+
<pane id="Favorites" />
|
|
100
127
|
<pane id="ProjectPane">
|
|
101
128
|
<subPane>
|
|
102
129
|
<PATH>
|
|
@@ -147,6 +174,24 @@
|
|
|
147
174
|
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
|
148
175
|
</PATH_ELEMENT>
|
|
149
176
|
</PATH>
|
|
177
|
+
<PATH>
|
|
178
|
+
<PATH_ELEMENT>
|
|
179
|
+
<option name="myItemId" value="mongo_followable" />
|
|
180
|
+
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
|
|
181
|
+
</PATH_ELEMENT>
|
|
182
|
+
<PATH_ELEMENT>
|
|
183
|
+
<option name="myItemId" value="mongo_followable" />
|
|
184
|
+
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
|
185
|
+
</PATH_ELEMENT>
|
|
186
|
+
<PATH_ELEMENT>
|
|
187
|
+
<option name="myItemId" value="spec" />
|
|
188
|
+
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
|
189
|
+
</PATH_ELEMENT>
|
|
190
|
+
<PATH_ELEMENT>
|
|
191
|
+
<option name="myItemId" value="mongo_mapper" />
|
|
192
|
+
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
|
|
193
|
+
</PATH_ELEMENT>
|
|
194
|
+
</PATH>
|
|
150
195
|
<PATH>
|
|
151
196
|
<PATH_ELEMENT>
|
|
152
197
|
<option name="myItemId" value="mongo_followable" />
|
|
@@ -199,7 +244,7 @@
|
|
|
199
244
|
</PATH>
|
|
200
245
|
</subPane>
|
|
201
246
|
</pane>
|
|
202
|
-
<pane id="
|
|
247
|
+
<pane id="Scope" />
|
|
203
248
|
</panes>
|
|
204
249
|
</component>
|
|
205
250
|
<component name="RecentsManager">
|
|
@@ -208,6 +253,24 @@
|
|
|
208
253
|
</key>
|
|
209
254
|
</component>
|
|
210
255
|
<component name="RunManager">
|
|
256
|
+
<configuration default="true" type="RubyRunConfigurationType" factoryName="Ruby">
|
|
257
|
+
<module name="" />
|
|
258
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
|
259
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="" />
|
|
260
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
|
261
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
|
262
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
|
263
|
+
<envs />
|
|
264
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
|
265
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" track_test_folders="true" runner="rcov">
|
|
266
|
+
<COVERAGE_PATTERN ENABLED="true">
|
|
267
|
+
<PATTERN REGEXPS="/.rvm/" INCLUDED="false" />
|
|
268
|
+
</COVERAGE_PATTERN>
|
|
269
|
+
</EXTENSION>
|
|
270
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="" />
|
|
271
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
|
272
|
+
<method />
|
|
273
|
+
</configuration>
|
|
211
274
|
<list size="0" />
|
|
212
275
|
</component>
|
|
213
276
|
<component name="ShelveChangesManager" show_recycled="false" />
|
|
@@ -333,51 +396,49 @@
|
|
|
333
396
|
<state line="6" column="48" selection-start="301" selection-end="301" vertical-scroll-proportion="0.13043478" />
|
|
334
397
|
</provider>
|
|
335
398
|
</entry>
|
|
336
|
-
<entry file="file://$PROJECT_DIR$/spec/
|
|
399
|
+
<entry file="file://$PROJECT_DIR$/spec/spec_helper.rb">
|
|
337
400
|
<provider selected="true" editor-type-id="text-editor">
|
|
338
|
-
<state line="
|
|
339
|
-
<folding />
|
|
340
|
-
</state>
|
|
401
|
+
<state line="24" column="42" selection-start="786" selection-end="786" vertical-scroll-proportion="0.5217391" />
|
|
341
402
|
</provider>
|
|
342
403
|
</entry>
|
|
343
|
-
<entry file="file://$PROJECT_DIR$/
|
|
404
|
+
<entry file="file://$PROJECT_DIR$/mongo_followable.gemspec">
|
|
344
405
|
<provider selected="true" editor-type-id="text-editor">
|
|
345
|
-
<state line="
|
|
346
|
-
<folding />
|
|
347
|
-
</state>
|
|
406
|
+
<state line="10" column="48" selection-start="408" selection-end="408" vertical-scroll-proportion="0.2173913" />
|
|
348
407
|
</provider>
|
|
349
408
|
</entry>
|
|
350
|
-
<entry file="file://$PROJECT_DIR$/
|
|
409
|
+
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/version.rb">
|
|
351
410
|
<provider selected="true" editor-type-id="text-editor">
|
|
352
|
-
<state line="
|
|
411
|
+
<state line="1" column="18" selection-start="41" selection-end="41" vertical-scroll-proportion="0.02173913">
|
|
353
412
|
<folding />
|
|
354
413
|
</state>
|
|
355
414
|
</provider>
|
|
356
415
|
</entry>
|
|
357
|
-
<entry file="file://$PROJECT_DIR$/mongo_followable.
|
|
416
|
+
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/follower.rb">
|
|
358
417
|
<provider selected="true" editor-type-id="text-editor">
|
|
359
|
-
<state line="
|
|
418
|
+
<state line="160" column="34" selection-start="4901" selection-end="4901" vertical-scroll-proportion="0.0">
|
|
360
419
|
<folding />
|
|
361
420
|
</state>
|
|
362
421
|
</provider>
|
|
363
422
|
</entry>
|
|
364
|
-
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/
|
|
423
|
+
<entry file="file://$PROJECT_DIR$/lib/mongo_followable/followable.rb">
|
|
365
424
|
<provider selected="true" editor-type-id="text-editor">
|
|
366
|
-
<state line="
|
|
425
|
+
<state line="127" column="36" selection-start="3865" selection-end="3865" vertical-scroll-proportion="0.0">
|
|
367
426
|
<folding />
|
|
368
427
|
</state>
|
|
369
428
|
</provider>
|
|
370
429
|
</entry>
|
|
371
|
-
<entry file="file://$PROJECT_DIR$/
|
|
430
|
+
<entry file="file://$PROJECT_DIR$/README.rdoc">
|
|
372
431
|
<provider selected="true" editor-type-id="text-editor">
|
|
373
|
-
<state line="
|
|
432
|
+
<state line="53" column="83" selection-start="1649" selection-end="1649" vertical-scroll-proportion="0.0">
|
|
374
433
|
<folding />
|
|
375
434
|
</state>
|
|
376
435
|
</provider>
|
|
377
436
|
</entry>
|
|
378
|
-
<entry file="file://$PROJECT_DIR$/
|
|
437
|
+
<entry file="file://$PROJECT_DIR$/spec/mongo/followable_spec.rb">
|
|
379
438
|
<provider selected="true" editor-type-id="text-editor">
|
|
380
|
-
<state line="
|
|
439
|
+
<state line="216" column="9" selection-start="4887" selection-end="4887" vertical-scroll-proportion="0.7826087">
|
|
440
|
+
<folding />
|
|
441
|
+
</state>
|
|
381
442
|
</provider>
|
|
382
443
|
</entry>
|
|
383
444
|
</component>
|
data/README.rdoc
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Now works for both Mongoid and Mongo_Mapper!
|
|
4
4
|
|
|
5
|
+
see http://www.thesika.info/articles/mongo_followable_update for details
|
|
6
|
+
|
|
5
7
|
== Installation
|
|
6
8
|
|
|
7
9
|
In console:
|
|
@@ -27,7 +29,7 @@ Now you can set authorization:
|
|
|
27
29
|
current_user.set_authorization('user', 'game') # now current_user cannot follow User and Game model
|
|
28
30
|
current_user.unset_authorization('User', 'Game')
|
|
29
31
|
|
|
30
|
-
And then you can follow
|
|
32
|
+
And then you can follow and unfollow:
|
|
31
33
|
|
|
32
34
|
@group = Group.new
|
|
33
35
|
@group.save
|
|
@@ -36,11 +38,21 @@ And then you can follow a model:
|
|
|
36
38
|
current_user.unfollow(@group)
|
|
37
39
|
current_user.unfollow_all
|
|
38
40
|
|
|
41
|
+
current_user.follow(*array_of_objects_to_follow) # follow an array of objects
|
|
42
|
+
current_user.unfollow(*array_of_objects_to_follow) # unfollow
|
|
43
|
+
|
|
39
44
|
or,
|
|
40
45
|
|
|
41
46
|
@group.unfollowed(current_user)
|
|
42
47
|
@group.unfollowed_all
|
|
43
48
|
|
|
49
|
+
It's also possible to pass a block:
|
|
50
|
+
|
|
51
|
+
current_user.follow(u1, u2, u3, u4...) { |user| user.name == 'Jeremy Lin' }
|
|
52
|
+
current_user.unfollow(u1, u2, u3, u4...) { |user| user.followee_of? 'Kobe Bryant' }
|
|
53
|
+
|
|
54
|
+
@group.unfollowed(u1, u2, u3...) { |user| user.ever_follow.include @some_user }
|
|
55
|
+
|
|
44
56
|
You can also judge whether a model is a follower of another model or a model is a followee of another model:
|
|
45
57
|
|
|
46
58
|
current_user.follower_of?(@group)
|
|
@@ -109,7 +109,11 @@ module Mongo
|
|
|
109
109
|
rebuild_instances(self.followers)
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
def unfollowed(*models)
|
|
112
|
+
def unfollowed(*models, &block)
|
|
113
|
+
if block_given?
|
|
114
|
+
models.delete_if { |model| !yield(model) }
|
|
115
|
+
end
|
|
116
|
+
|
|
113
117
|
models.each do |model|
|
|
114
118
|
unless model == self or !self.followee_of?(model) or !model.follower_of?(self) or self.cannot_followed.include?(model.class.name) or model.cannot_follow.include?(self.class.name)
|
|
115
119
|
model.followees.by_model(self).first.destroy
|
|
@@ -123,7 +123,11 @@ module Mongo
|
|
|
123
123
|
|
|
124
124
|
# follow some model
|
|
125
125
|
|
|
126
|
-
def follow(*models)
|
|
126
|
+
def follow(*models, &block)
|
|
127
|
+
if block_given?
|
|
128
|
+
models.delete_if { |model| !yield(model) }
|
|
129
|
+
end
|
|
130
|
+
|
|
127
131
|
models.each do |model|
|
|
128
132
|
unless model == self or self.follower_of?(model) or model.followee_of?(self) or self.cannot_follow.include?(model.class.name) or model.cannot_followed.include?(self.class.name)
|
|
129
133
|
model.followers.create!(:f_type => self.class.name, :f_id => self.id.to_s)
|
|
@@ -138,7 +142,11 @@ module Mongo
|
|
|
138
142
|
|
|
139
143
|
# unfollow some model
|
|
140
144
|
|
|
141
|
-
def unfollow(*models)
|
|
145
|
+
def unfollow(*models, &block)
|
|
146
|
+
if block_given?
|
|
147
|
+
models.delete_if { |model| !yield(model) }
|
|
148
|
+
end
|
|
149
|
+
|
|
142
150
|
models.each do |model|
|
|
143
151
|
unless model == self or !self.follower_of?(model) or !model.followee_of?(self) or self.cannot_follow.include?(model.class.name) or model.cannot_followed.include?(self.class.name)
|
|
144
152
|
model.followers.by_model(self).first.destroy
|
|
@@ -183,4 +183,38 @@ describe Mongo::Followable do
|
|
|
183
183
|
|
|
184
184
|
end
|
|
185
185
|
end
|
|
186
|
+
|
|
187
|
+
describe User do
|
|
188
|
+
|
|
189
|
+
context "begins" do
|
|
190
|
+
|
|
191
|
+
before do
|
|
192
|
+
@u = User.new
|
|
193
|
+
@u.save
|
|
194
|
+
|
|
195
|
+
@v = User.new
|
|
196
|
+
@v.save
|
|
197
|
+
|
|
198
|
+
@w = User.new
|
|
199
|
+
@w.save
|
|
200
|
+
|
|
201
|
+
@g = Group.new
|
|
202
|
+
@g.save
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
it "block test" do
|
|
207
|
+
@u.follow(@v, @w, @g) {|m| m.class == User}
|
|
208
|
+
|
|
209
|
+
@u.all_followees.should =~ [@v, @w]
|
|
210
|
+
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "block test unfollow" do
|
|
214
|
+
@u.unfollow(@v, @w, @g) {|m| m.followee_of? @u}
|
|
215
|
+
|
|
216
|
+
@u.all_followees.should == []
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|
|
186
220
|
end
|
metadata
CHANGED
|
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
|
5
5
|
segments:
|
|
6
6
|
- 0
|
|
7
7
|
- 2
|
|
8
|
-
-
|
|
9
|
-
version: 0.2.
|
|
8
|
+
- 3
|
|
9
|
+
version: 0.2.3
|
|
10
10
|
platform: ruby
|
|
11
11
|
authors:
|
|
12
12
|
- Jie Fan
|
|
@@ -14,7 +14,7 @@ autorequire:
|
|
|
14
14
|
bindir: bin
|
|
15
15
|
cert_chain: []
|
|
16
16
|
|
|
17
|
-
date: 2012-02-
|
|
17
|
+
date: 2012-02-15 00:00:00 -05:00
|
|
18
18
|
default_executable:
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|