mongoid-likeable 3.0.2 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/README.md +9 -1
- data/lib/mongoid/likeable.rb +6 -2
- data/mongoid-likeable.gemspec +1 -1
- data/test/mongoid_likeable_test.rb +9 -0
- data/test/test_helper.rb +4 -2
- metadata +18 -37
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: beb40afa034fee3ce48271478f2696a2ad7a64da
|
4
|
+
data.tar.gz: 795f59cb6f1ab81860b901b731ad36a9213d81c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 892539d5492964552c47269dbd6bd4883d47a59f33c6d1337255184a0194edeb50906b7000dd9212667a7693130e088eda0f0f76348f394a47990fdae4ab04a1
|
7
|
+
data.tar.gz: cf993ad44cbfd38452f50d55620083627d1a724ee727b39c29d36fd732490875c3c032e830442905e4c25a3d51de7b2020af1f588a571aad704533352c7d3d4e
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
# mongoid-likeable
|
1
|
+
# mongoid-likeable
|
2
|
+
[![Build Status](https://secure.travis-ci.org/diowa/mongoid-likeable.png?branch=master)](https://travis-ci.org/diowa/mongoid-likeable)
|
3
|
+
[![Dependency Status](https://gemnasium.com/diowa/mongoid-likeable.png)](https://gemnasium.com/diowa/mongoid-likeable)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/diowa/mongoid-likeable.png)](https://codeclimate.com/github/diowa/mongoid-likeable)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/diowa/mongoid-likeable/badge.png?branch=master)](https://coveralls.io/r/diowa/mongoid-likeable)
|
2
6
|
|
3
7
|
Add like to your Mongoid documents.
|
4
8
|
This is a fork of `tombell/mongoid-voteable` for people who only need likes.
|
@@ -15,6 +19,10 @@ or add the gem to your `Gemfile`
|
|
15
19
|
|
16
20
|
gem 'mongoid-likeable'
|
17
21
|
|
22
|
+
## Thread safety
|
23
|
+
|
24
|
+
This gem is thread safe. It uses a mutex on the likeable object.
|
25
|
+
|
18
26
|
## Usage
|
19
27
|
|
20
28
|
Include the `Mongoid::Likeable` module into your models you want to like.
|
data/lib/mongoid/likeable.rb
CHANGED
@@ -6,13 +6,16 @@ module Mongoid
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
included do
|
9
|
+
LIKEABLE_MUTEX = Mutex.new
|
10
|
+
|
9
11
|
field :likes, type: Integer, default: 0
|
10
12
|
field :likers, type: Array, default: []
|
11
13
|
end
|
12
14
|
|
13
15
|
def like(liker)
|
14
16
|
id = liker_id(liker)
|
15
|
-
|
17
|
+
return if liked? id
|
18
|
+
LIKEABLE_MUTEX.synchronize do
|
16
19
|
inc :likes, 1
|
17
20
|
push :likers, id
|
18
21
|
touch
|
@@ -21,7 +24,8 @@ module Mongoid
|
|
21
24
|
|
22
25
|
def unlike(liker)
|
23
26
|
id = liker_id(liker)
|
24
|
-
|
27
|
+
return unless liked? id
|
28
|
+
LIKEABLE_MUTEX.synchronize do
|
25
29
|
inc :likes, -1
|
26
30
|
pull :likers, id
|
27
31
|
touch
|
data/mongoid-likeable.gemspec
CHANGED
@@ -69,6 +69,15 @@ class TestMongoidLikeable < MiniTest::Unit::TestCase
|
|
69
69
|
assert_equal 1, @story.likes
|
70
70
|
end
|
71
71
|
|
72
|
+
def test_successful_like_return_value
|
73
|
+
assert_equal true, @story.like(@simon)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_failed_like_return_value
|
77
|
+
@story.like @simon
|
78
|
+
assert_equal nil, @story.like(@simon)
|
79
|
+
end
|
80
|
+
|
72
81
|
def test_knows_who_has_liked
|
73
82
|
@story.like @simon
|
74
83
|
assert @story.liked? @simon
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-likeable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: '4.0'
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Diowa
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongoid
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,81 +27,71 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: database_cleaner
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rake
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: debugger
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: delorean
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: coveralls
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- -
|
87
|
+
- - '>='
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '0'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- -
|
94
|
+
- - '>='
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '0'
|
110
97
|
description: Add likes to your Mongoid documents
|
@@ -131,31 +118,25 @@ files:
|
|
131
118
|
- test/test_helper.rb
|
132
119
|
homepage: https://github.com/diowa/mongoid-likeable
|
133
120
|
licenses: []
|
121
|
+
metadata: {}
|
134
122
|
post_install_message:
|
135
123
|
rdoc_options: []
|
136
124
|
require_paths:
|
137
125
|
- lib
|
138
126
|
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
-
none: false
|
140
127
|
requirements:
|
141
|
-
- -
|
128
|
+
- - '>='
|
142
129
|
- !ruby/object:Gem::Version
|
143
130
|
version: '0'
|
144
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
132
|
requirements:
|
147
|
-
- -
|
133
|
+
- - '>='
|
148
134
|
- !ruby/object:Gem::Version
|
149
135
|
version: '0'
|
150
136
|
requirements: []
|
151
137
|
rubyforge_project: mongoid-likeable
|
152
|
-
rubygems_version:
|
138
|
+
rubygems_version: 2.0.3
|
153
139
|
signing_key:
|
154
|
-
specification_version:
|
140
|
+
specification_version: 4
|
155
141
|
summary: Add likes to your Mongoid documents
|
156
|
-
test_files:
|
157
|
-
- test/models/story.rb
|
158
|
-
- test/models/story_with_timestamps.rb
|
159
|
-
- test/models/user.rb
|
160
|
-
- test/mongoid_likeable_test.rb
|
161
|
-
- test/test_helper.rb
|
142
|
+
test_files: []
|