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.
Files changed (3) hide show
  1. data/CHANGELOG.markdown +4 -0
  2. data/lib/has_karma.rb +21 -5
  3. metadata +2 -2
@@ -1,3 +1,7 @@
1
+ 2009-02-11
2
+ ==========
3
+ * Merge in xlash's bugfix for PostgreSQL and his has\_karma patch for multi-model support.
4
+
1
5
  2008-12-02
2
6
  ==========
3
7
  * Merge in maddox's README typo fix and his ActiveSupport.Dependency patch
@@ -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
- self.karma_voteable.sum(:vote, options_for_karma(options))
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
- conditions = ["u.id = ?" , self[:id] ]
44
- joins = ["inner join votes v on #{karma_voteable.table_name}.id = v.voteable_id", "inner join #{self.class.table_name} u on u.id = #{karma_voteable.name.tableize}.#{self.class.name.foreign_key}"]
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.10
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-01-07 00:00:00 -08:00
15
+ date: 2009-02-11 00:00:00 -08:00
16
16
  default_executable:
17
17
  dependencies: []
18
18