peteonrails-vote_fu 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +4 -0
- data/lib/has_karma.rb +21 -5
- metadata +2 -2
data/CHANGELOG.markdown
CHANGED
data/lib/has_karma.rb
CHANGED
@@ -6,6 +6,9 @@ module PeteOnRails
|
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base.extend ClassMethods
|
9
|
+
class << base
|
10
|
+
attr_accessor :karmatic_objects
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
module ClassMethods
|
@@ -15,9 +18,13 @@ module PeteOnRails
|
|
15
18
|
#{voteable_type.to_s.classify}
|
16
19
|
end
|
17
20
|
RUBY
|
18
|
-
|
19
21
|
include PeteOnRails::VoteFu::Karma::InstanceMethods
|
20
22
|
extend PeteOnRails::VoteFu::Karma::SingletonMethods
|
23
|
+
if self.karmatic_objects.nil?
|
24
|
+
self.karmatic_objects = [eval(voteable_type.to_s.classify)]
|
25
|
+
else
|
26
|
+
self.karmatic_objects.push(eval(voteable_type.to_s.classify))
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
@@ -35,13 +42,22 @@ module PeteOnRails
|
|
35
42
|
# This module contains instance methods
|
36
43
|
module InstanceMethods
|
37
44
|
def karma(options = {})
|
45
|
+
#FIXME cannot have 2 models imapcting the karma simultaneously
|
38
46
|
# count the total number of votes on all of the voteable objects that are related to this object
|
39
|
-
|
47
|
+
#2009-01-30 GuillaumeNM The following line is not SQLite3 compatible, because boolean are stored as 'f' or 't', not '1', or '0'
|
48
|
+
#self.karma_voteable.sum(:vote, options_for_karma(options))
|
49
|
+
#self.karma_voteable.find(:all, options_for_karma(options)).length
|
50
|
+
karma_value = 0
|
51
|
+
self.class.karmatic_objects.each do |object|
|
52
|
+
karma_value += object.find(:all, options_for_karma(object, options)).length
|
53
|
+
end
|
54
|
+
return karma_value
|
40
55
|
end
|
41
56
|
|
42
|
-
def options_for_karma (options = {})
|
43
|
-
|
44
|
-
|
57
|
+
def options_for_karma (object, options = {})
|
58
|
+
#GuillaumeNM : 2009-01-30 Adding condition for SQLite3
|
59
|
+
conditions = ["u.id = ? AND vote = ?" , self[:id] , true]
|
60
|
+
joins = ["inner join votes v on #{object.table_name}.id = v.voteable_id", "inner join #{self.class.table_name} u on u.id = #{object.name.tableize}.#{self.class.name.foreign_key}"]
|
45
61
|
{ :joins => joins.join(" "), :conditions => conditions }.update(options)
|
46
62
|
end
|
47
63
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peteonrails-vote_fu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Jackson
|
@@ -12,7 +12,7 @@ autorequire:
|
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
14
|
|
15
|
-
date: 2009-
|
15
|
+
date: 2009-02-11 00:00:00 -08:00
|
16
16
|
default_executable:
|
17
17
|
dependencies: []
|
18
18
|
|