voteable_mongoid 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mongoid/voteable.rb +12 -12
  2. metadata +3 -3
@@ -20,8 +20,8 @@ module Mongoid
20
20
 
21
21
 
22
22
  def self.vote_point(klass = self, options = nil)
23
- VOTE_POINT[self] ||= {}
24
- VOTE_POINT[self][klass] ||= options
23
+ VOTE_POINT[self.name] ||= {}
24
+ VOTE_POINT[self.name][klass.name] ||= options
25
25
  end
26
26
 
27
27
 
@@ -46,11 +46,11 @@ module Mongoid
46
46
  if value == :up
47
47
  push_field = :up_voter_ids
48
48
  pull_field = :down_voter_ids
49
- point_delta = VOTE_POINT[self][self][:up] - VOTE_POINT[self][self][:down]
49
+ point_delta = VOTE_POINT[name][name][:up] - VOTE_POINT[name][name][:down]
50
50
  else
51
51
  push_field = :down_voter_ids
52
52
  pull_field = :up_voter_ids
53
- point_delta = -VOTE_POINT[self][self][:up] + VOTE_POINT[self][self][:down]
53
+ point_delta = -VOTE_POINT[name][name][:up] + VOTE_POINT[name][name][:down]
54
54
  end
55
55
 
56
56
  collection.update({
@@ -80,17 +80,17 @@ module Mongoid
80
80
  '$push' => { push_field => voter_id },
81
81
  '$inc' => {
82
82
  :votes_count => +1,
83
- :votes_point => VOTE_POINT[self][self][value]
83
+ :votes_point => VOTE_POINT[name][name][value]
84
84
  }
85
85
  })
86
86
  end
87
87
 
88
- VOTE_POINT[self].each do |klass, value_point|
89
- next unless association = associations[klass.name.underscore]
88
+ VOTE_POINT[name].each do |class_name, value_point|
89
+ next unless association = associations[class_name.underscore]
90
90
  next unless foreign_key = options[association.options[:foreign_key].to_sym]
91
91
  foreign_key = BSON::ObjectID(foreign_key) if foreign_key.is_a?(String)
92
92
 
93
- klass.collection.update({ :_id => foreign_key }, {
93
+ class_name.constantize.collection.update({ :_id => foreign_key }, {
94
94
  '$inc' => options[:revote] ? {
95
95
  :votes_point => ( value == :up ?
96
96
  value_point[:up] - value_point[:down] :
@@ -106,14 +106,14 @@ module Mongoid
106
106
 
107
107
 
108
108
  def vote(options)
109
- VOTE_POINT[self.class].each do |klass, value_point|
110
- next unless association = self.class.associations[klass.name.underscore]
109
+ VOTE_POINT[self.class.name].each do |class_name, value_point|
110
+ next unless association = self.class.associations[class_name.underscore]
111
111
  next unless foreign_key = association.options[:foreign_key]
112
112
  options[foreign_key] = read_attribute(foreign_key)
113
113
  end
114
114
 
115
- options[:votee_id] = _id
116
- options[:revote] = !vote_value(options[:voter_id]).nil?
115
+ options[:votee_id] ||= _id
116
+ options[:revote] ||= !vote_value(options[:voter_id]).nil?
117
117
 
118
118
  self.class.vote(options)
119
119
  end
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: 17
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 1
10
- version: 0.3.1
9
+ - 2
10
+ version: 0.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Nguyen