acts_rateable 0.0.8 → 0.0.9
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.
- checksums.yaml +5 -13
- data/lib/acts_rateable/acts_rateable.rb +2 -2
- data/lib/acts_rateable/count.rb +4 -4
- data/lib/acts_rateable/rate.rb +4 -4
- data/lib/acts_rateable/rating.rb +4 -4
- data/lib/acts_rateable/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
ZGJjY2NkYzRlMjE2OWNiYmU1ODFmOGYzZWYwMWJkMTc4OGQ2ZGY4OA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e5ae76f712ab61e271a04c9795b38f78b6108a9
|
4
|
+
data.tar.gz: 3bf4cac295b9e8fba704a4b867f632cc10628347
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZWU3YmUzNWUzNTgyMWE0Nzc3MmUwNDA2OTIyZmYxNjc0MWY1ZTgwNjU0ZWE5
|
11
|
-
MDNkY2U5YWZlZWI5Yjk4YmRjMmE0Y2ZmZTc1ODMwZjVjNWU0MjI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZDNlMDljMTExZTViMzhhODdkNmY1MjlkY2Q2YzU0OWQ2Y2ViY2YxYzkwMWZk
|
14
|
-
ZjhlZGM1ODA0ZmY3YWVmNGY5NWZjZGViMWQ0OTRjYzI5YzhlYjRkODQ5NjMx
|
15
|
-
YmI3NzAzNTI4NDE3MzFhY2Q1NDg1OGViYjZiZjAwMWUzNDk4ZDI=
|
6
|
+
metadata.gz: a75321111d7f6121123804ae20b731c9143e39d53cd0fe6b009d69e5c44fe33a060b0a8b4bf0d43c5cda7d97727fb18985fdf9e04160b550e74238f7356baa5d
|
7
|
+
data.tar.gz: 0dccf046d313d6bf3f133e49a631f7ce3696048778f465e8f9cb736220597590ed1ef71730045fe94cd6b67ab2d7ab5bb6b1cbc98964ba8306bad197912d5dda
|
@@ -28,8 +28,8 @@ module ActsRateable
|
|
28
28
|
}
|
29
29
|
|
30
30
|
after_create do
|
31
|
-
|
32
|
-
ActsRateable::Count.where({resource_id: self.id, resource_type: self.class.name}).first_or_initialize.save
|
31
|
+
ActsRateable::Rating.where({resource_id: self.id, resource_type: self.class.base_class.name }).first_or_initialize.save
|
32
|
+
ActsRateable::Count.where({resource_id: self.id, resource_type: self.class.base_class.name }).first_or_initialize.save
|
33
33
|
end
|
34
34
|
|
35
35
|
include LocalInstanceMethods
|
data/lib/acts_rateable/count.rb
CHANGED
@@ -14,16 +14,16 @@ module ActsRateable
|
|
14
14
|
|
15
15
|
def self.get_totals(author)
|
16
16
|
sql = "SELECT COUNT(*) total_ratings, SUM(value) rating_sum, AVG(value) rating_avg, "+
|
17
|
-
"(SELECT COUNT(DISTINCT author_id) FROM ar_rates WHERE author_type = '#{author.class.name}') rated_count, "+
|
18
|
-
"((SELECT COUNT(*) from ar_rates WHERE author_type = '#{author.class.name}') / (SELECT COUNT(DISTINCT author_id) FROM ar_rates WHERE author_type = '#{author.class.name}')) avg_num_ratings "+
|
19
|
-
"FROM ar_rates WHERE author_type = '#{author.class.name}'"
|
17
|
+
"(SELECT COUNT(DISTINCT author_id) FROM ar_rates WHERE author_type = '#{author.class.base_class.name}') rated_count, "+
|
18
|
+
"((SELECT COUNT(*) from ar_rates WHERE author_type = '#{author.class.base_class.name}') / (SELECT COUNT(DISTINCT author_id) FROM ar_rates WHERE author_type = '#{author.class.base_class.name}')) avg_num_ratings "+
|
19
|
+
"FROM ar_rates WHERE author_type = '#{author.class.base_class.name}'"
|
20
20
|
# RETURNS = { "total_ratings"=>"", "rating_sum"=>"", "rating_avg"=>"", "rated_count"=>"", "avg_num_ratings"=>"" }
|
21
21
|
ActsRateable::Rate.connection.execute(sql).first
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.values_for(author)
|
25
25
|
sql = "SELECT COUNT(*) total_ratings, COALESCE(SUM(value),0) rating_sum, COALESCE(AVG(value),0) rating_avg "+
|
26
|
-
"FROM ar_rates WHERE author_type = '#{author.class.name}' and author_id = '#{author.id}'"
|
26
|
+
"FROM ar_rates WHERE author_type = '#{author.class.base_class.name}' and author_id = '#{author.id}'"
|
27
27
|
# RETURNS = {"total_ratings"=>"", "rating_sum"=>"", "rating_avg"=>""}
|
28
28
|
ActsRateable::Rate.connection.execute(sql).first
|
29
29
|
end
|
data/lib/acts_rateable/rate.rb
CHANGED
@@ -19,8 +19,8 @@ module ActsRateable
|
|
19
19
|
|
20
20
|
def self.rated?(resource, author)
|
21
21
|
rate = where({
|
22
|
-
author_type: author.class.name, author_id: author.id,
|
23
|
-
resource_type: resource.class.name, resource_id: resource.id
|
22
|
+
author_type: author.class.base_class.name, author_id: author.id,
|
23
|
+
resource_type: resource.class.base_class.name, resource_id: resource.id
|
24
24
|
})
|
25
25
|
return rate if rate
|
26
26
|
return false
|
@@ -29,8 +29,8 @@ module ActsRateable
|
|
29
29
|
def self.create(author, resource, value)
|
30
30
|
return unless author && resource && value
|
31
31
|
atts = {
|
32
|
-
resource_type: resource.class.name, resource_id: resource.id,
|
33
|
-
author_type: author.class.name, author_id: author.id,
|
32
|
+
resource_type: resource.class.base_class.name, resource_id: resource.id,
|
33
|
+
author_type: author.class.base_class.name, author_id: author.id,
|
34
34
|
value: value
|
35
35
|
}
|
36
36
|
rate = where(atts.except(:value)).first_or_initialize(atts)
|
data/lib/acts_rateable/rating.rb
CHANGED
@@ -15,16 +15,16 @@ module ActsRateable
|
|
15
15
|
# RETURNS = { "total_ratings"=>"", "rating_sum"=>"", "rating_avg"=>"", "rated_count"=>"", "avg_num_ratings"=>"" }
|
16
16
|
def self.get_totals(resource)
|
17
17
|
sql = "SELECT COUNT(*) total_ratings, SUM(value) rating_sum, AVG(value) rating_avg, "+
|
18
|
-
"(SELECT COUNT(DISTINCT resource_id) FROM ar_rates WHERE resource_type = '#{resource.class.name}') rated_count, "+
|
19
|
-
"((SELECT COUNT(*) from ar_rates WHERE resource_type = '#{resource.class.name}') / (SELECT COUNT(DISTINCT resource_id) FROM ar_rates WHERE resource_type = '#{resource.class.name}')) avg_num_ratings "+
|
20
|
-
"FROM ar_rates WHERE resource_type = '#{resource.class.name}'"
|
18
|
+
"(SELECT COUNT(DISTINCT resource_id) FROM ar_rates WHERE resource_type = '#{resource.class.base_class.name}') rated_count, "+
|
19
|
+
"((SELECT COUNT(*) from ar_rates WHERE resource_type = '#{resource.class.base_class.name}') / (SELECT COUNT(DISTINCT resource_id) FROM ar_rates WHERE resource_type = '#{resource.class.base_class.name}')) avg_num_ratings "+
|
20
|
+
"FROM ar_rates WHERE resource_type = '#{resource.class.base_class.name}'"
|
21
21
|
ActsRateable::Rate.connection.execute(sql).first
|
22
22
|
end
|
23
23
|
|
24
24
|
# RETURNS = {"total_ratings"=>"", "rating_sum"=>"", "rating_avg"=>""}
|
25
25
|
def self.values_for(resource)
|
26
26
|
sql = "SELECT COUNT(*) total_ratings, COALESCE(SUM(value),0) rating_sum, COALESCE(AVG(value),0) rating_avg "+
|
27
|
-
"FROM ar_rates WHERE resource_type = '#{resource.class.name}' and resource_id = '#{resource.id}'"
|
27
|
+
"FROM ar_rates WHERE resource_type = '#{resource.class.base_class.name}' and resource_id = '#{resource.id}'"
|
28
28
|
ActsRateable::Rate.connection.execute(sql).first
|
29
29
|
end
|
30
30
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_rateable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ty Rauber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Rails 3 Bayesian Ratings Gem
|
14
14
|
email:
|
@@ -39,12 +39,12 @@ require_paths:
|
|
39
39
|
- lib
|
40
40
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '0'
|
50
50
|
requirements: []
|