mongoid_rateable 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,2 +1,2 @@
1
1
  rvm_gemset_create_on_use_flag=1
2
- rvm use 1.9.2@mongoid_rateable
2
+ rvm use 1.9.3@mongoid_rateable
data/Gemfile.lock CHANGED
@@ -1,18 +1,17 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activemodel (3.1.0)
5
- activesupport (= 3.1.0)
6
- bcrypt-ruby (~> 3.0.0)
4
+ activemodel (3.2.1)
5
+ activesupport (= 3.2.1)
7
6
  builder (~> 3.0.0)
7
+ activesupport (3.2.1)
8
8
  i18n (~> 0.6)
9
- activesupport (3.1.0)
10
9
  multi_json (~> 1.0)
11
- bcrypt-ruby (3.0.1)
12
- bson (1.4.0)
13
- bson_ext (1.4.0)
10
+ bson (1.5.2)
11
+ bson_ext (1.5.2)
12
+ bson (= 1.5.2)
14
13
  builder (3.0.0)
15
- database_cleaner (0.6.7)
14
+ database_cleaner (0.7.1)
16
15
  diff-lcs (1.1.3)
17
16
  git (1.2.5)
18
17
  i18n (0.6.0)
@@ -20,28 +19,30 @@ GEM
20
19
  bundler (~> 1.0)
21
20
  git (>= 1.2.5)
22
21
  rake
23
- mongo (1.3.1)
24
- bson (>= 1.3.1)
25
- mongoid (2.2.1)
26
- activemodel (~> 3.0)
27
- mongo (>= 1.3, < 1.4)
22
+ json (1.6.5)
23
+ mongo (1.5.2)
24
+ bson (= 1.5.2)
25
+ mongoid (2.4.3)
26
+ activemodel (~> 3.1)
27
+ mongo (~> 1.3)
28
28
  tzinfo (~> 0.3.22)
29
- multi_json (1.0.3)
30
- rake (0.9.2)
31
- rdoc (3.9.4)
32
- rspec (2.6.0)
33
- rspec-core (~> 2.6.0)
34
- rspec-expectations (~> 2.6.0)
35
- rspec-mocks (~> 2.6.0)
36
- rspec-core (2.6.4)
37
- rspec-expectations (2.6.0)
29
+ multi_json (1.0.4)
30
+ rake (0.9.2.2)
31
+ rdoc (3.12)
32
+ json (~> 1.4)
33
+ rspec (2.8.0)
34
+ rspec-core (~> 2.8.0)
35
+ rspec-expectations (~> 2.8.0)
36
+ rspec-mocks (~> 2.8.0)
37
+ rspec-core (2.8.0)
38
+ rspec-expectations (2.8.0)
38
39
  diff-lcs (~> 1.1.2)
39
- rspec-mocks (2.6.0)
40
- simplecov (0.5.3)
40
+ rspec-mocks (2.8.0)
41
+ simplecov (0.5.4)
41
42
  multi_json (~> 1.0.3)
42
43
  simplecov-html (~> 0.5.3)
43
44
  simplecov-html (0.5.3)
44
- tzinfo (0.3.29)
45
+ tzinfo (0.3.31)
45
46
 
46
47
  PLATFORMS
47
48
  ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -23,92 +23,88 @@ module Mongoid
23
23
  scope :highest_rated, ->(limit=10) { order_by([:rating, :desc]).limit(limit) }
24
24
  end
25
25
 
26
- module InstanceMethods
27
-
28
- def rate(mark, rater, weight = 1)
29
- validate_rating!(mark)
30
- unrate_without_rating_update(rater)
31
- total_mark = mark.to_i*weight.to_i
32
- self.rates += total_mark
33
- self.rating_marks.new(:rater_id => rater.id, :mark => mark, :rater_class => rater.class.to_s, :weight => weight)
34
- self.weighted_rate_count += weight
35
- update_rating
36
- end
26
+ def rate(mark, rater, weight = 1)
27
+ validate_rating!(mark)
28
+ unrate_without_rating_update(rater)
29
+ total_mark = mark.to_i*weight.to_i
30
+ self.rates += total_mark
31
+ self.rating_marks.new(:rater_id => rater.id, :mark => mark, :rater_class => rater.class.to_s, :weight => weight)
32
+ self.weighted_rate_count += weight
33
+ update_rating
34
+ end
37
35
 
38
- def unrate(rater)
39
- unrate_without_rating_update(rater)
40
- update_rating
41
- end
36
+ def unrate(rater)
37
+ unrate_without_rating_update(rater)
38
+ update_rating
39
+ end
42
40
 
43
- def rate_and_save(mark, rater, weight = 1)
44
- rate(mark, rater, weight)
45
- save
46
- end
41
+ def rate_and_save(mark, rater, weight = 1)
42
+ rate(mark, rater, weight)
43
+ save
44
+ end
47
45
 
48
- def unrate_and_save(rater)
49
- unrate(rater)
50
- save
51
- end
46
+ def unrate_and_save(rater)
47
+ unrate(rater)
48
+ save
49
+ end
52
50
 
53
- def rated?(rater = nil)
54
- if rater
55
- puts "Deprecated method, please use rated_by?"
56
- rated_by?(rater)
57
- else
58
- rate_count!=0
59
- end
51
+ def rated?(rater = nil)
52
+ if rater
53
+ puts "Deprecated method, please use rated_by?"
54
+ rated_by?(rater)
55
+ else
56
+ rate_count!=0
60
57
  end
58
+ end
61
59
 
62
- def rated_by?(rater)
63
- self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).count == 1
64
- end
60
+ def rated_by?(rater)
61
+ self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).count == 1
62
+ end
65
63
 
66
- def rating
67
- read_attribute(:rating)
68
- end
64
+ def rating
65
+ read_attribute(:rating)
66
+ end
69
67
 
70
- def rate_count
71
- self.rating_marks.size
72
- end
68
+ def rate_count
69
+ self.rating_marks.size
70
+ end
73
71
 
74
- def rate_weight
75
- check_weighted_rate_count
76
- read_attribute(:weighted_rate_count)
77
- end
72
+ def rate_weight
73
+ check_weighted_rate_count
74
+ read_attribute(:weighted_rate_count)
75
+ end
78
76
 
79
- protected
77
+ protected
80
78
 
81
- def validate_rating!(value)
82
- if (defined? self.class::RATING_RANGE) and (range = self.class::RATING_RANGE) and !range.include?(value.to_i)
83
- raise ArgumentError, "Rating not in range #{range}. Rating provided was #{value}."
84
- end
79
+ def validate_rating!(value)
80
+ if (defined? self.class::RATING_RANGE) and (range = self.class::RATING_RANGE) and !range.include?(value.to_i)
81
+ raise ArgumentError, "Rating not in range #{range}. Rating provided was #{value}."
85
82
  end
83
+ end
86
84
 
87
- def unrate_without_rating_update(rater)
88
- rmark = self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).first
89
- if rmark
90
- weight = (rmark.weight ||= 1)
91
- total_mark = rmark.mark.to_i*weight.to_i
92
- self.rates -= total_mark
93
- self.weighted_rate_count -= weight
94
- rmark.delete
95
- end
85
+ def unrate_without_rating_update(rater)
86
+ rmark = self.rating_marks.where(:rater_id => rater.id, :rater_class => rater.class.to_s).first
87
+ if rmark
88
+ weight = (rmark.weight ||= 1)
89
+ total_mark = rmark.mark.to_i*weight.to_i
90
+ self.rates -= total_mark
91
+ self.weighted_rate_count -= weight
92
+ rmark.delete
96
93
  end
94
+ end
97
95
 
98
- def update_rating
99
- check_weighted_rate_count
100
- rt = (self.rates.to_f / self.weighted_rate_count.to_f) unless self.rating_marks.blank?
101
- write_attribute(:rating, rt)
102
- end
96
+ def update_rating
97
+ check_weighted_rate_count
98
+ rt = (self.rates.to_f / self.weighted_rate_count.to_f) unless self.rating_marks.blank?
99
+ write_attribute(:rating, rt)
100
+ end
103
101
 
104
- def check_weighted_rate_count
105
- #migration from old version
106
- wrc = read_attribute(:weighted_rate_count).to_i
107
- if (wrc==0 && rate_count!=0)
108
- write_attribute(:weighted_rate_count, self.rating_marks.size)
109
- end
102
+ def check_weighted_rate_count
103
+ #migration from old version
104
+ wrc = read_attribute(:weighted_rate_count).to_i
105
+ if (wrc==0 && rate_count!=0)
106
+ write_attribute(:weighted_rate_count, self.rating_marks.size)
110
107
  end
111
-
112
108
  end
113
109
  end
114
110
  end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{mongoid_rateable}
8
- s.version = "0.1.6"
7
+ s.name = "mongoid_rateable"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Peter Savichev (proton)}]
12
- s.date = %q{2011-09-27}
13
- s.description = %q{Provides fields and methods for the rating manipulation on Mongoid documents.}
14
- s.email = %q{psavichev@gmail.com}
11
+ s.authors = ["Peter Savichev (proton)"]
12
+ s.date = "2012-02-01"
13
+ s.description = "Provides fields and methods for the rating manipulation on Mongoid documents."
14
+ s.email = "psavichev@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc",
@@ -37,11 +37,11 @@ Gem::Specification.new do |s|
37
37
  "spec/rateable_spec.rb",
38
38
  "spec/spec_helper.rb"
39
39
  ]
40
- s.homepage = %q{http://github.com/proton/mongoid_rateable}
41
- s.licenses = [%q{MIT}]
42
- s.require_paths = [%q{lib}]
43
- s.rubygems_version = %q{1.8.6}
44
- s.summary = %q{Rating functionality for Mongoid documents}
40
+ s.homepage = "http://github.com/proton/mongoid_rateable"
41
+ s.licenses = ["MIT"]
42
+ s.require_paths = ["lib"]
43
+ s.rubygems_version = "1.8.10"
44
+ s.summary = "Rating functionality for Mongoid documents"
45
45
 
46
46
  if s.respond_to? :specification_version then
47
47
  s.specification_version = 3
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid_rateable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-27 00:00:00.000000000Z
12
+ date: 2012-02-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
16
- requirement: &89686630 !ruby/object:Gem::Requirement
16
+ requirement: &74800700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *89686630
24
+ version_requirements: *74800700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mongoid
27
- requirement: &89686300 !ruby/object:Gem::Requirement
27
+ requirement: &74800110 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *89686300
35
+ version_requirements: *74800110
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &89685960 !ruby/object:Gem::Requirement
38
+ requirement: &74799410 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *89685960
46
+ version_requirements: *74799410
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &89685640 !ruby/object:Gem::Requirement
49
+ requirement: &74798460 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.2
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *89685640
57
+ version_requirements: *74798460
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &89685310 !ruby/object:Gem::Requirement
60
+ requirement: &74613850 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.4.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *89685310
68
+ version_requirements: *74613850
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &89685000 !ruby/object:Gem::Requirement
71
+ requirement: &74612950 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *89685000
79
+ version_requirements: *74612950
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &89684700 !ruby/object:Gem::Requirement
82
+ requirement: &74612350 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 2.0.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *89684700
90
+ version_requirements: *74612350
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: database_cleaner
93
- requirement: &89684390 !ruby/object:Gem::Requirement
93
+ requirement: &74612100 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *89684390
101
+ version_requirements: *74612100
102
102
  description: Provides fields and methods for the rating manipulation on Mongoid documents.
103
103
  email: psavichev@gmail.com
104
104
  executables: []
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
141
  version: '0'
142
142
  segments:
143
143
  - 0
144
- hash: 137369441
144
+ hash: -395726893
145
145
  required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  none: false
147
147
  requirements:
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project:
153
- rubygems_version: 1.8.6
153
+ rubygems_version: 1.8.10
154
154
  signing_key:
155
155
  specification_version: 3
156
156
  summary: Rating functionality for Mongoid documents