mongoid-likeable 4.0 → 4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: beb40afa034fee3ce48271478f2696a2ad7a64da
4
- data.tar.gz: 795f59cb6f1ab81860b901b731ad36a9213d81c7
3
+ metadata.gz: d7ab27bc064a7dcef21812624431d8753ab09468
4
+ data.tar.gz: 6fdb93ff39733743b70f696a6fa4164b72beae29
5
5
  SHA512:
6
- metadata.gz: 892539d5492964552c47269dbd6bd4883d47a59f33c6d1337255184a0194edeb50906b7000dd9212667a7693130e088eda0f0f76348f394a47990fdae4ab04a1
7
- data.tar.gz: cf993ad44cbfd38452f50d55620083627d1a724ee727b39c29d36fd732490875c3c032e830442905e4c25a3d51de7b2020af1f588a571aad704533352c7d3d4e
6
+ metadata.gz: 2e13db4dc2662872836dec79c155feaa3111645c1c07b133768007262d27bcca7bc1f408821d2b918fffab34bc487f41ff7b5a498549e984f31ed313e4377653
7
+ data.tar.gz: 25933c7334d8786104a9ada57df4f71fdbd2adc0a5c0d07062d96fc21537e6be152db45dda0fe10ce6d60c69857329236c5e385eaf9d0698be789df42fc2d1d7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ 4.1
2
+ ---
3
+ * Improved code
4
+ * Thread safety without mutex
5
+
1
6
  4.0
2
7
  ---
3
8
  * Thread safety
data/README.md CHANGED
@@ -21,7 +21,7 @@ or add the gem to your `Gemfile`
21
21
 
22
22
  ## Thread safety
23
23
 
24
- This gem is thread safe. It uses a mutex on the likeable object.
24
+ This gem is thread safe.
25
25
 
26
26
  ## Usage
27
27
 
@@ -6,8 +6,6 @@ module Mongoid
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- LIKEABLE_MUTEX = Mutex.new
10
-
11
9
  field :likes, type: Integer, default: 0
12
10
  field :likers, type: Array, default: []
13
11
  end
@@ -15,21 +13,15 @@ module Mongoid
15
13
  def like(liker)
16
14
  id = liker_id(liker)
17
15
  return if liked? id
18
- LIKEABLE_MUTEX.synchronize do
19
- inc :likes, 1
20
- push :likers, id
21
- touch
22
- end
16
+ push :likers, id
17
+ update_likers
23
18
  end
24
19
 
25
20
  def unlike(liker)
26
21
  id = liker_id(liker)
27
22
  return unless liked? id
28
- LIKEABLE_MUTEX.synchronize do
29
- inc :likes, -1
30
- pull :likers, id
31
- touch
32
- end
23
+ pull :likers, id
24
+ update_likers
33
25
  end
34
26
 
35
27
  def liked?(liker)
@@ -38,7 +30,6 @@ module Mongoid
38
30
  end
39
31
 
40
32
  private
41
-
42
33
  def liker_id(liker)
43
34
  if liker.respond_to?(:_id)
44
35
  liker._id
@@ -46,5 +37,9 @@ module Mongoid
46
37
  liker
47
38
  end
48
39
  end
40
+
41
+ def update_likers
42
+ update_attribute :likes, likers.size
43
+ end
49
44
  end
50
45
  end
@@ -3,7 +3,7 @@ $:.push File.expand_path('../lib', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'mongoid-likeable'
6
- s.version = '4.0'
6
+ s.version = '4.1'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ['Diowa']
9
9
  s.email = ['dev@diowa.com']
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = 'mongoid-likeable'
15
15
 
16
- s.add_dependency 'mongoid', '~> 3.1.2'
16
+ s.add_dependency 'mongoid', '~> 3.1.3'
17
17
 
18
18
  s.add_development_dependency 'database_cleaner'
19
19
  s.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-likeable
3
3
  version: !ruby/object:Gem::Version
4
- version: '4.0'
4
+ version: '4.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diowa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-09 00:00:00.000000000 Z
11
+ date: 2013-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 3.1.2
19
+ version: 3.1.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: 3.1.2
26
+ version: 3.1.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: database_cleaner
29
29
  requirement: !ruby/object:Gem::Requirement