mongoid_rateable 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "mongoid", "5.2.0"
6
+
7
+ group :development do
8
+ gem "bundler"
9
+ gem "jeweler", "~> 2.1.1"
10
+ gem "simplecov", "~> 0.7", :require => false
11
+ gem "yard"
12
+ gem "rspec", ">= 3.0.0"
13
+ gem "appraisal"
14
+ gem "coveralls", :require => false
15
+ gem "database_cleaner", ">= 0.8.0"
16
+ end
@@ -0,0 +1,126 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (4.2.7.1)
5
+ activesupport (= 4.2.7.1)
6
+ builder (~> 3.1)
7
+ activesupport (4.2.7.1)
8
+ i18n (~> 0.7)
9
+ json (~> 1.7, >= 1.7.7)
10
+ minitest (~> 5.1)
11
+ thread_safe (~> 0.3, >= 0.3.4)
12
+ tzinfo (~> 1.1)
13
+ addressable (2.5.0)
14
+ public_suffix (~> 2.0, >= 2.0.2)
15
+ appraisal (2.1.0)
16
+ bundler
17
+ rake
18
+ thor (>= 0.14.0)
19
+ bson (4.2.1)
20
+ builder (3.2.3)
21
+ coveralls (0.8.19)
22
+ json (>= 1.8, < 3)
23
+ simplecov (~> 0.12.0)
24
+ term-ansicolor (~> 1.3)
25
+ thor (~> 0.19.1)
26
+ tins (~> 1.6)
27
+ database_cleaner (1.5.3)
28
+ descendants_tracker (0.0.4)
29
+ thread_safe (~> 0.3, >= 0.3.1)
30
+ diff-lcs (1.3)
31
+ docile (1.1.5)
32
+ faraday (0.9.2)
33
+ multipart-post (>= 1.2, < 3)
34
+ git (1.3.0)
35
+ github_api (0.11.3)
36
+ addressable (~> 2.3)
37
+ descendants_tracker (~> 0.0.1)
38
+ faraday (~> 0.8, < 0.10)
39
+ hashie (>= 1.2)
40
+ multi_json (>= 1.7.5, < 2.0)
41
+ nokogiri (~> 1.6.0)
42
+ oauth2
43
+ hashie (3.4.6)
44
+ highline (1.7.8)
45
+ i18n (0.7.0)
46
+ jeweler (2.1.2)
47
+ builder
48
+ bundler (>= 1.0)
49
+ git (>= 1.2.5)
50
+ github_api (~> 0.11.0)
51
+ highline (>= 1.6.15)
52
+ nokogiri (>= 1.5.10)
53
+ rake
54
+ rdoc
55
+ semver
56
+ json (1.8.6)
57
+ jwt (1.5.6)
58
+ mini_portile2 (2.1.0)
59
+ minitest (5.10.1)
60
+ mongo (2.4.1)
61
+ bson (>= 4.2.1, < 5.0.0)
62
+ mongoid (5.2.0)
63
+ activemodel (~> 4.0)
64
+ mongo (>= 2.4.1, < 3.0.0)
65
+ origin (~> 2.3)
66
+ tzinfo (>= 0.3.37)
67
+ multi_json (1.12.1)
68
+ multi_xml (0.6.0)
69
+ multipart-post (2.0.0)
70
+ nokogiri (1.6.8.1)
71
+ mini_portile2 (~> 2.1.0)
72
+ oauth2 (1.3.0)
73
+ faraday (>= 0.8, < 0.11)
74
+ jwt (~> 1.0)
75
+ multi_json (~> 1.3)
76
+ multi_xml (~> 0.5)
77
+ rack (>= 1.2, < 3)
78
+ origin (2.3.0)
79
+ public_suffix (2.0.5)
80
+ rack (2.0.1)
81
+ rake (12.0.0)
82
+ rdoc (5.0.0)
83
+ rspec (3.5.0)
84
+ rspec-core (~> 3.5.0)
85
+ rspec-expectations (~> 3.5.0)
86
+ rspec-mocks (~> 3.5.0)
87
+ rspec-core (3.5.4)
88
+ rspec-support (~> 3.5.0)
89
+ rspec-expectations (3.5.0)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.5.0)
92
+ rspec-mocks (3.5.0)
93
+ diff-lcs (>= 1.2.0, < 2.0)
94
+ rspec-support (~> 3.5.0)
95
+ rspec-support (3.5.0)
96
+ semver (1.0.1)
97
+ simplecov (0.12.0)
98
+ docile (~> 1.1.0)
99
+ json (>= 1.8, < 3)
100
+ simplecov-html (~> 0.10.0)
101
+ simplecov-html (0.10.0)
102
+ term-ansicolor (1.4.0)
103
+ tins (~> 1.0)
104
+ thor (0.19.4)
105
+ thread_safe (0.3.5)
106
+ tins (1.13.0)
107
+ tzinfo (1.2.2)
108
+ thread_safe (~> 0.1)
109
+ yard (0.9.8)
110
+
111
+ PLATFORMS
112
+ ruby
113
+
114
+ DEPENDENCIES
115
+ appraisal
116
+ bundler
117
+ coveralls
118
+ database_cleaner (>= 0.8.0)
119
+ jeweler (~> 2.1.1)
120
+ mongoid (= 5.2.0)
121
+ rspec (>= 3.0.0)
122
+ simplecov (~> 0.7)
123
+ yard
124
+
125
+ BUNDLED WITH
126
+ 1.14.3
@@ -0,0 +1,16 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "http://rubygems.org"
4
+
5
+ gem "mongoid", "6.1.0"
6
+
7
+ group :development do
8
+ gem "bundler"
9
+ gem "jeweler", "~> 2.1.1"
10
+ gem "simplecov", "~> 0.7", :require => false
11
+ gem "yard"
12
+ gem "rspec", ">= 3.0.0"
13
+ gem "appraisal"
14
+ gem "coveralls", :require => false
15
+ gem "database_cleaner", ">= 0.8.0"
16
+ end
@@ -0,0 +1,122 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (5.0.1)
5
+ activesupport (= 5.0.1)
6
+ activesupport (5.0.1)
7
+ concurrent-ruby (~> 1.0, >= 1.0.2)
8
+ i18n (~> 0.7)
9
+ minitest (~> 5.1)
10
+ tzinfo (~> 1.1)
11
+ addressable (2.5.0)
12
+ public_suffix (~> 2.0, >= 2.0.2)
13
+ appraisal (2.1.0)
14
+ bundler
15
+ rake
16
+ thor (>= 0.14.0)
17
+ bson (4.2.1)
18
+ builder (3.2.3)
19
+ concurrent-ruby (1.0.4)
20
+ coveralls (0.8.19)
21
+ json (>= 1.8, < 3)
22
+ simplecov (~> 0.12.0)
23
+ term-ansicolor (~> 1.3)
24
+ thor (~> 0.19.1)
25
+ tins (~> 1.6)
26
+ database_cleaner (1.5.3)
27
+ descendants_tracker (0.0.4)
28
+ thread_safe (~> 0.3, >= 0.3.1)
29
+ diff-lcs (1.3)
30
+ docile (1.1.5)
31
+ faraday (0.9.2)
32
+ multipart-post (>= 1.2, < 3)
33
+ git (1.3.0)
34
+ github_api (0.11.3)
35
+ addressable (~> 2.3)
36
+ descendants_tracker (~> 0.0.1)
37
+ faraday (~> 0.8, < 0.10)
38
+ hashie (>= 1.2)
39
+ multi_json (>= 1.7.5, < 2.0)
40
+ nokogiri (~> 1.6.0)
41
+ oauth2
42
+ hashie (3.4.6)
43
+ highline (1.7.8)
44
+ i18n (0.7.0)
45
+ jeweler (2.1.2)
46
+ builder
47
+ bundler (>= 1.0)
48
+ git (>= 1.2.5)
49
+ github_api (~> 0.11.0)
50
+ highline (>= 1.6.15)
51
+ nokogiri (>= 1.5.10)
52
+ rake
53
+ rdoc
54
+ semver
55
+ json (2.0.3)
56
+ jwt (1.5.6)
57
+ mini_portile2 (2.1.0)
58
+ minitest (5.10.1)
59
+ mongo (2.4.1)
60
+ bson (>= 4.2.1, < 5.0.0)
61
+ mongoid (6.1.0)
62
+ activemodel (~> 5.0)
63
+ mongo (>= 2.4.1, < 3.0.0)
64
+ multi_json (1.12.1)
65
+ multi_xml (0.6.0)
66
+ multipart-post (2.0.0)
67
+ nokogiri (1.6.8.1)
68
+ mini_portile2 (~> 2.1.0)
69
+ oauth2 (1.3.0)
70
+ faraday (>= 0.8, < 0.11)
71
+ jwt (~> 1.0)
72
+ multi_json (~> 1.3)
73
+ multi_xml (~> 0.5)
74
+ rack (>= 1.2, < 3)
75
+ public_suffix (2.0.5)
76
+ rack (2.0.1)
77
+ rake (12.0.0)
78
+ rdoc (5.0.0)
79
+ rspec (3.5.0)
80
+ rspec-core (~> 3.5.0)
81
+ rspec-expectations (~> 3.5.0)
82
+ rspec-mocks (~> 3.5.0)
83
+ rspec-core (3.5.4)
84
+ rspec-support (~> 3.5.0)
85
+ rspec-expectations (3.5.0)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.5.0)
88
+ rspec-mocks (3.5.0)
89
+ diff-lcs (>= 1.2.0, < 2.0)
90
+ rspec-support (~> 3.5.0)
91
+ rspec-support (3.5.0)
92
+ semver (1.0.1)
93
+ simplecov (0.12.0)
94
+ docile (~> 1.1.0)
95
+ json (>= 1.8, < 3)
96
+ simplecov-html (~> 0.10.0)
97
+ simplecov-html (0.10.0)
98
+ term-ansicolor (1.4.0)
99
+ tins (~> 1.0)
100
+ thor (0.19.4)
101
+ thread_safe (0.3.5)
102
+ tins (1.13.0)
103
+ tzinfo (1.2.2)
104
+ thread_safe (~> 0.1)
105
+ yard (0.9.8)
106
+
107
+ PLATFORMS
108
+ ruby
109
+
110
+ DEPENDENCIES
111
+ appraisal
112
+ bundler
113
+ coveralls
114
+ database_cleaner (>= 0.8.0)
115
+ jeweler (~> 2.1.1)
116
+ mongoid (= 6.1.0)
117
+ rspec (>= 3.0.0)
118
+ simplecov (~> 0.7)
119
+ yard
120
+
121
+ BUNDLED WITH
122
+ 1.14.3
@@ -1,4 +1,3 @@
1
- require 'mongoid_rateable/version'
2
1
  require 'mongoid_rateable/rateable'
3
2
  require 'mongoid_rateable/rating'
4
3
 
@@ -7,7 +7,7 @@ module Mongoid
7
7
 
8
8
  module ClassMethods
9
9
  def rateable options = {}
10
- class_eval do
10
+ class_eval do
11
11
  self.send :include, Mongoid::Rateable
12
12
  self.rate_config options
13
13
  end
@@ -26,8 +26,8 @@ module Mongoid
26
26
 
27
27
  index({"rating_marks.rater_id" => 1, "rating_marks.rater_class" => 1})
28
28
 
29
- scope :unrated, where(:rating.exists => false)
30
- scope :rated, where(:rating.exists => true)
29
+ scope :unrated, -> { where(:rating.exists => false) }
30
+ scope :rated, -> { where(:rating.exists => true) }
31
31
  scope :rated_by, ->(rater) { where("rating_marks.rater_id" => rater.id, "rating_marks.rater_class" => rater.class.to_s) }
32
32
  scope :with_rating, ->(range) { where(:rating.gte => range.begin, :rating.lte => range.end) }
33
33
  scope :highest_rated, ->(limit=10) { order_by([:rating, :desc]).limit(limit) }
@@ -46,7 +46,7 @@ module Mongoid
46
46
  def in_rating_range?(value)
47
47
  range = rating_range if respond_to?(:rating_range)
48
48
  range ? range.include?(value.to_i) : true
49
- end
49
+ end
50
50
 
51
51
  # macro to create dynamic :rating_range class method!
52
52
  # can now even take an Array and find the range of values!
@@ -95,7 +95,7 @@ module Mongoid
95
95
  self.instance_eval(&block)
96
96
  end
97
97
  else
98
- raise ArgumentError, "Must take symbol or block argument"
98
+ raise ArgumentError, "Must take symbol or block argument"
99
99
  end
100
100
  end
101
101
  end # class methods
@@ -104,12 +104,12 @@ module Mongoid
104
104
  case rater
105
105
  when Array
106
106
  rater.each{|rater| rate(mark, rater, weight)}
107
- else
107
+ else
108
108
  if !rater
109
109
  unless respond_to?(:default_rater)
110
110
  raise ArgumentError, "No rater argument and no default_rater specified"
111
111
  end
112
- rater = default_rater
112
+ rater = default_rater
113
113
  end
114
114
  validate_rater!(rater)
115
115
  validate_rating!(mark)
@@ -126,7 +126,7 @@ module Mongoid
126
126
  case rater
127
127
  when Array
128
128
  rater.each{|rater| unrate(mark, rater, weight)}
129
- else
129
+ else
130
130
  unrate_without_rating_update(rater)
131
131
  update_rating
132
132
  end
@@ -136,7 +136,7 @@ module Mongoid
136
136
  case rater
137
137
  when Array
138
138
  rater.each{|rater| rate_and_save(mark, rater, weight)}
139
- else
139
+ else
140
140
  rate(mark, rater, weight)
141
141
  save
142
142
  end
@@ -146,7 +146,7 @@ module Mongoid
146
146
  case rater
147
147
  when Array
148
148
  rater.each{|rater| unrate_and_save(mark, rater, weight)}
149
- else
149
+ else
150
150
  unrate(rater)
151
151
  save
152
152
  end
@@ -160,7 +160,7 @@ module Mongoid
160
160
  case rater
161
161
  when Array
162
162
  rater.each{|rater| rated_by(mark, rater, weight)}
163
- else
163
+ else
164
164
  self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).count == 1
165
165
  end
166
166
  end
@@ -197,6 +197,15 @@ module Mongoid
197
197
  r ? r.mark : nil
198
198
  end
199
199
 
200
+ def user_marks(raters)
201
+ if raters.map{|x| x.class}.uniq.count > 1
202
+ raise ArgumentError, "Raters all must be of same class."
203
+ return
204
+ end
205
+ r = self.rating_marks.in(:rater_id => raters.map(&:id), :rater_class => raters.first.class.to_s)
206
+ r ? r.inject(Hash.new(0)) { |h, e| h[e.rater_id] = e.mark ; h } : nil
207
+ end
208
+
200
209
  protected
201
210
 
202
211
  def validate_rater!(rater)
@@ -228,7 +237,7 @@ module Mongoid
228
237
  rt = (self.rates.to_f / self.weighted_rate_count.to_f) unless self.rating_marks.blank?
229
238
  write_attribute(:rating, rt)
230
239
  delta = (self.rating && self.previous_rating) ? rating-previous_rating : 0.0
231
- write_attribute(:rating_delta, delta)
240
+ write_attribute(:rating_delta, delta)
232
241
  end
233
242
 
234
243
  def check_weighted_rate_count
@@ -5,6 +5,6 @@ class RatingMark
5
5
  embedded_in :rateable, :polymorphic => true
6
6
  field :mark, :type => Integer
7
7
  field :rater_class, :type => String
8
- field :rater_id, :type => Moped::BSON::ObjectId
8
+ field :rater_id, :type => Mongoid::VERSION.start_with?('3') ? Moped::BSON::ObjectId : BSON::ObjectId
9
9
  field :weight, :type => Integer, :default => 1
10
10
  end
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: mongoid_rateable 0.3.3 ruby lib
5
+ # stub: mongoid_rateable 0.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
- s.name = "mongoid_rateable"
9
- s.version = "0.3.3"
8
+ s.name = "mongoid_rateable".freeze
9
+ s.version = "0.4.0"
10
10
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.require_paths = ["lib"]
13
- s.authors = ["Peter Savichev (proton)"]
14
- s.date = "2014-06-21"
15
- s.description = "Provides fields and methods for the rating manipulation on Mongoid documents."
16
- s.email = "psavichev@gmail.com"
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Peter Savichev (proton)".freeze]
14
+ s.date = "2017-01-28"
15
+ s.description = "Provides fields and methods for the rating manipulation on Mongoid documents.".freeze
16
+ s.email = "psavichev@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
18
18
  "LICENSE.txt",
19
19
  "README.rdoc",
@@ -21,61 +21,75 @@ Gem::Specification.new do |s|
21
21
  ]
22
22
  s.files = [
23
23
  ".rspec",
24
- ".rvmrc",
24
+ ".ruby-version",
25
25
  ".travis.yml",
26
+ "Appraisals",
26
27
  "CHANGELOG.md",
27
28
  "Gemfile",
28
- "Gemfile.lock",
29
29
  "LICENSE.txt",
30
30
  "README.rdoc",
31
31
  "Rakefile",
32
32
  "TODO",
33
33
  "VERSION",
34
+ "gemfiles/mongoid_3.gemfile",
35
+ "gemfiles/mongoid_3.gemfile.lock",
36
+ "gemfiles/mongoid_4.gemfile",
37
+ "gemfiles/mongoid_4.gemfile.lock",
38
+ "gemfiles/mongoid_5.gemfile",
39
+ "gemfiles/mongoid_5.gemfile.lock",
40
+ "gemfiles/mongoid_6.gemfile",
41
+ "gemfiles/mongoid_6.gemfile.lock",
34
42
  "lib/mongoid_rateable.rb",
35
43
  "lib/mongoid_rateable/rateable.rb",
36
44
  "lib/mongoid_rateable/rating.rb",
37
- "lib/mongoid_rateable/version.rb",
38
45
  "mongoid_rateable.gemspec",
39
46
  "spec/models/article.rb",
40
47
  "spec/models/comment.rb",
41
48
  "spec/models/post.rb",
42
49
  "spec/models/user.rb",
43
50
  "spec/rateable_spec.rb",
44
- "spec/spec_helper.rb"
51
+ "spec/spec_helper.rb",
52
+ "spec/support/database_cleaner.rb"
45
53
  ]
46
- s.homepage = "http://github.com/proton/mongoid_rateable"
47
- s.licenses = ["MIT"]
48
- s.rubygems_version = "2.2.2"
49
- s.summary = "Rating functionality for Mongoid documents"
54
+ s.homepage = "http://github.com/proton/mongoid_rateable".freeze
55
+ s.licenses = ["MIT".freeze]
56
+ s.rubygems_version = "2.5.2".freeze
57
+ s.summary = "Rating functionality for Mongoid documents".freeze
50
58
 
51
59
  if s.respond_to? :specification_version then
52
60
  s.specification_version = 4
53
61
 
54
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<mongoid>, ["~> 3.0"])
56
- s.add_development_dependency(%q<bundler>, ["~> 1"])
57
- s.add_development_dependency(%q<jeweler>, ["~> 1.6"])
58
- s.add_development_dependency(%q<simplecov>, ["~> 0.4"])
59
- s.add_development_dependency(%q<rdoc>, ["~> 3"])
60
- s.add_development_dependency(%q<rspec>, ["~> 2.0"])
61
- s.add_development_dependency(%q<database_cleaner>, ["~> 0"])
63
+ s.add_runtime_dependency(%q<mongoid>.freeze, [">= 3.0"])
64
+ s.add_development_dependency(%q<bundler>.freeze, [">= 0"])
65
+ s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.1.1"])
66
+ s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.7"])
67
+ s.add_development_dependency(%q<yard>.freeze, [">= 0"])
68
+ s.add_development_dependency(%q<rspec>.freeze, [">= 3.0.0"])
69
+ s.add_development_dependency(%q<appraisal>.freeze, [">= 0"])
70
+ s.add_development_dependency(%q<coveralls>.freeze, [">= 0"])
71
+ s.add_development_dependency(%q<database_cleaner>.freeze, [">= 0.8.0"])
62
72
  else
63
- s.add_dependency(%q<mongoid>, ["~> 3.0"])
64
- s.add_dependency(%q<bundler>, ["~> 1"])
65
- s.add_dependency(%q<jeweler>, ["~> 1.6"])
66
- s.add_dependency(%q<simplecov>, ["~> 0.4"])
67
- s.add_dependency(%q<rdoc>, ["~> 3"])
68
- s.add_dependency(%q<rspec>, ["~> 2.0"])
69
- s.add_dependency(%q<database_cleaner>, ["~> 0"])
73
+ s.add_dependency(%q<mongoid>.freeze, [">= 3.0"])
74
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
75
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.1.1"])
76
+ s.add_dependency(%q<simplecov>.freeze, ["~> 0.7"])
77
+ s.add_dependency(%q<yard>.freeze, [">= 0"])
78
+ s.add_dependency(%q<rspec>.freeze, [">= 3.0.0"])
79
+ s.add_dependency(%q<appraisal>.freeze, [">= 0"])
80
+ s.add_dependency(%q<coveralls>.freeze, [">= 0"])
81
+ s.add_dependency(%q<database_cleaner>.freeze, [">= 0.8.0"])
70
82
  end
71
83
  else
72
- s.add_dependency(%q<mongoid>, ["~> 3.0"])
73
- s.add_dependency(%q<bundler>, ["~> 1"])
74
- s.add_dependency(%q<jeweler>, ["~> 1.6"])
75
- s.add_dependency(%q<simplecov>, ["~> 0.4"])
76
- s.add_dependency(%q<rdoc>, ["~> 3"])
77
- s.add_dependency(%q<rspec>, ["~> 2.0"])
78
- s.add_dependency(%q<database_cleaner>, ["~> 0"])
84
+ s.add_dependency(%q<mongoid>.freeze, [">= 3.0"])
85
+ s.add_dependency(%q<bundler>.freeze, [">= 0"])
86
+ s.add_dependency(%q<jeweler>.freeze, ["~> 2.1.1"])
87
+ s.add_dependency(%q<simplecov>.freeze, ["~> 0.7"])
88
+ s.add_dependency(%q<yard>.freeze, [">= 0"])
89
+ s.add_dependency(%q<rspec>.freeze, [">= 3.0.0"])
90
+ s.add_dependency(%q<appraisal>.freeze, [">= 0"])
91
+ s.add_dependency(%q<coveralls>.freeze, [">= 0"])
92
+ s.add_dependency(%q<database_cleaner>.freeze, [">= 0.8.0"])
79
93
  end
80
94
  end
81
95