voteable_mongoid 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.
@@ -19,6 +19,8 @@ module Mongoid
19
19
  # In this case, validation can be skip to maximize performance
20
20
 
21
21
  def self.vote(options)
22
+ options.symbolize_keys!
23
+
22
24
  votee_id = options[:votee_id]
23
25
  voter_id = options[:voter_id]
24
26
  value = options[:value]
@@ -27,7 +29,7 @@ module Mongoid
27
29
  voter_id = BSON::ObjectID(voter_id) if voter_id.is_a?(String)
28
30
 
29
31
  if options[:revote]
30
- if value == :up
32
+ if value.to_sym == :up
31
33
  push_field = :up_voter_ids
32
34
  pull_field = :down_voter_ids
33
35
  point_delta = +2
@@ -50,7 +52,7 @@ module Mongoid
50
52
  })
51
53
 
52
54
  else # new vote
53
- if value == :up
55
+ if value.to_sym == :up
54
56
  push_field = :up_voter_ids
55
57
  point_delta = +1
56
58
  else
@@ -73,7 +75,16 @@ module Mongoid
73
75
  end
74
76
  end
75
77
 
76
- def vote_value(voter_id)
78
+ def vote_value(x)
79
+ voter_id = case x
80
+ when String
81
+ BSON::ObjectID(x)
82
+ when BSON::ObjectID
83
+ x
84
+ else
85
+ x.id
86
+ end
87
+
77
88
  return :up if up_voter_ids.try(:include?, voter_id)
78
89
  return :down if down_voter_ids.try(:include?, voter_id)
79
90
  end
data/lib/mongoid/voter.rb CHANGED
@@ -40,6 +40,8 @@ module Mongoid
40
40
 
41
41
 
42
42
  def vote(options, vote_value = nil)
43
+ options.symbolize_keys!
44
+
43
45
  if options.is_a?(Hash)
44
46
  votee = options[:votee]
45
47
  else
@@ -54,8 +56,10 @@ module Mongoid
54
56
  votee_class = options[:votee_type].constantize
55
57
  end
56
58
 
57
- unless options.has_key?(:revote)
58
- options[:revote] = voted?(options)
59
+ options[:revote] = if options.has_key?(:revote)
60
+ !options[:revote].blank?
61
+ else
62
+ options.has_key?(:new) ? options[:new].blank? : voted?(options)
59
63
  end
60
64
 
61
65
  options[:voter_id] = _id
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voteable_mongoid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Nguyen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-02 00:00:00 +07:00
18
+ date: 2010-09-03 00:00:00 +07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency