activerecord-reputation-system 1.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +29 -198
- data/lib/activerecord-reputation-system.rb +1 -0
- data/lib/reputation_system.rb +6 -6
- data/lib/reputation_system/base.rb +16 -6
- data/lib/reputation_system/{evaluation.rb → evaluation_methods.rb} +32 -13
- data/lib/reputation_system/models/evaluation.rb +73 -0
- data/lib/reputation_system/models/reputation.rb +211 -0
- data/lib/reputation_system/models/reputation_message.rb +49 -0
- data/lib/reputation_system/network.rb +2 -0
- data/lib/reputation_system/query_builder.rb +4 -4
- data/lib/reputation_system/{reputation.rb → reputation_methods.rb} +5 -15
- data/lib/reputation_system/{scope.rb → scope_methods.rb} +2 -2
- data/lib/reputation_system/version.rb +1 -1
- data/spec/reputation_system/base_spec.rb +46 -6
- data/spec/reputation_system/{evaluation_spec.rb → evaluation_methods_spec.rb} +52 -9
- data/spec/{models/rs_evaluation_spec.rb → reputation_system/models/evaluation_spec.rb} +8 -8
- data/spec/{models/rs_reputation_message_spec.rb → reputation_system/models/reputation_message_spec.rb} +10 -10
- data/spec/reputation_system/models/reputation_spec.rb +136 -0
- data/spec/reputation_system/{reputation_spec.rb → reputation_methods_spec.rb} +2 -2
- data/spec/reputation_system/{scope_spec.rb → scope_methods_spec.rb} +0 -0
- data/spec/spec_helper.rb +2 -4
- metadata +15 -14
- data/lib/models/rs_evaluation.rb +0 -69
- data/lib/models/rs_reputation.rb +0 -204
- data/lib/models/rs_reputation_message.rb +0 -46
- data/spec/models/rs_reputation_spec.rb +0 -119
data/README.md
CHANGED
@@ -4,10 +4,12 @@ The Active Record Reputation System helps you discover more about your applicati
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
+
* If you are updating to version 2 from version older, you should check out [migration guide](https://github.com/twitter/activerecord-reputation-system/wiki/Migrate-to-Version-2.0).
|
8
|
+
|
7
9
|
Add to Gemfile:
|
8
10
|
|
9
11
|
```ruby
|
10
|
-
gem 'activerecord-reputation-system'
|
12
|
+
gem 'activerecord-reputation-system'
|
11
13
|
```
|
12
14
|
|
13
15
|
Run:
|
@@ -20,7 +22,7 @@ rake db:migrate
|
|
20
22
|
|
21
23
|
* Please do the installation on every upgrade as it may include new migration files.
|
22
24
|
|
23
|
-
##
|
25
|
+
## Quick Start
|
24
26
|
|
25
27
|
Let's say we want to keep track of user karma in Q&A site where user karma is sum of questioning skill and answering skill. Questioning skill is sum of votes for user's questions and Answering skill is sum of average rating of user's answers. This can be defined as follow:
|
26
28
|
```ruby
|
@@ -31,16 +33,13 @@ class User < ActiveRecord::Base
|
|
31
33
|
has_reputation :karma,
|
32
34
|
:source => [
|
33
35
|
{ :reputation => :questioning_skill, :weight => 0.8 },
|
34
|
-
{ :reputation => :answering_skill }]
|
35
|
-
:aggregated_by => :sum
|
36
|
+
{ :reputation => :answering_skill }]
|
36
37
|
|
37
38
|
has_reputation :questioning_skill,
|
38
|
-
:source => { :reputation => :votes, :of => :questions }
|
39
|
-
:aggregated_by => :sum
|
39
|
+
:source => { :reputation => :votes, :of => :questions }
|
40
40
|
|
41
41
|
has_reputation :answering_skill,
|
42
|
-
:source => { :reputation => :avg_rating, :of => :answers }
|
43
|
-
:aggregated_by => :sum
|
42
|
+
:source => { :reputation => :avg_rating, :of => :answers }
|
44
43
|
end
|
45
44
|
|
46
45
|
class Answer < ActiveRecord::Base
|
@@ -57,8 +56,7 @@ class Question < ActiveRecord::Base
|
|
57
56
|
belongs_to :user
|
58
57
|
|
59
58
|
has_reputation :votes,
|
60
|
-
:source => :user
|
61
|
-
:aggregated_by => :sum
|
59
|
+
:source => :user
|
62
60
|
end
|
63
61
|
```
|
64
62
|
|
@@ -70,204 +68,46 @@ Once reputation system is defined, evaluations for answers and questions can be
|
|
70
68
|
|
71
69
|
Reputation value can be accessed as follow:
|
72
70
|
```ruby
|
73
|
-
@answer.reptuation_for(:avg_rating)
|
74
|
-
@question.reptuation_for(:votes)
|
71
|
+
@answer.reptuation_for(:avg_rating) #=> 3
|
72
|
+
@question.reptuation_for(:votes) #=> 1
|
75
73
|
@user.reptuation_for(:karma)
|
76
74
|
```
|
77
75
|
|
78
|
-
|
79
|
-
|
80
|
-
All reputations can be defined in their target ActiveRecord models like this:
|
81
|
-
```ruby
|
82
|
-
# Primary Reputation
|
83
|
-
has_reputation :name,
|
84
|
-
:source => source,
|
85
|
-
:aggregated_by => process,
|
86
|
-
:source_of => [{:reputation => name, :of => attribute}, ...],
|
87
|
-
:init_value => initial_value
|
88
|
-
|
89
|
-
# Non Primary Reputation
|
90
|
-
has_reputation :name,
|
91
|
-
:source => [{:reputation => name, :of => attribute, :weight => weight}, ...],
|
92
|
-
:aggregated_by => process,
|
93
|
-
:source_of => [{:reputation => name, :of => attribute}, ...],
|
94
|
-
:init_value => initial_value
|
95
|
-
```
|
96
|
-
* `:name` is the name of the reputation.
|
97
|
-
* `:source` is a source of the reputation. If it is primary reputation, it takes a class name as input. If it's a non-primary reputation, it takes one or more source definitions, which consist of:
|
98
|
-
* `:reputation` - name of reputation to be used as a source.
|
99
|
-
* `:of` - attribute name (It also accepts a proc as an argument) of the ActiveRecord model which has the source reputation. (default: :self)
|
100
|
-
* `:weight` (optional) - weight value to be used for aggregation (default: 1).
|
101
|
-
* `:aggregated_by` is a mathematical process to be used to aggregate reputation or evaluation values. The following processes are available (each value is weighted by a predefined weight):
|
102
|
-
* average - averages all values received.
|
103
|
-
* sum - sums up all the values received.
|
104
|
-
* product - multiplies all the values received.
|
105
|
-
* `:source_of` (optional) - just like active record association, you don't need to define this if a name can be derived from class name; otherwise if the reputation is used as a part of a source belonging to other reputations, you must define. It takes one or more source definitions, which consists of:
|
106
|
-
* `:reputation` - name of the reputation to be used as a source.
|
107
|
-
* `:of` - attribute name (It also accepts a proc as an argument) of the ActiveRecord model which has the source reputation. (default: :self)
|
108
|
-
* `:init_value` (optional) - initial reputation value assigned to new reputation. It is 0 for average and sum process and 1 for product by default.
|
109
|
-
|
110
|
-
## Evaluation
|
76
|
+
You can query for records using reputation value:
|
111
77
|
```ruby
|
112
|
-
|
113
|
-
add_evaluation(reputation_name, evaluation_value, source)
|
114
|
-
|
115
|
-
# Updates an existing evaluation of the reputation with the specified name by the specified source.
|
116
|
-
update_evaluation(reputation_name, evaluation_value, source)
|
117
|
-
|
118
|
-
# Adds an evaluation to the reputation with the specified name if it exists; otherwise it updates the existing reputation.
|
119
|
-
add_or_update_evaluation(reputation_name, evaluation_value, source)
|
120
|
-
|
121
|
-
# Deletes an evaluation from the reputation with the specified name submitted by the specified source. It returns nil if it does not exist.
|
122
|
-
delete_evaluation(reputation_name, source)
|
123
|
-
|
124
|
-
# Deletes an evaluation from the reputation with the specified name submitted by specified source. Raises an exception if it does not exist.
|
125
|
-
delete_evaluation!(reputation_name, source)
|
126
|
-
|
127
|
-
# Increase an evaluation value of the reputation with the specified name by given value.
|
128
|
-
increase_evaluation(reputation_name, value, source)
|
129
|
-
|
130
|
-
# Decrease an evaluation value of the reputation with the specified name by given value.
|
131
|
-
decrease_evaluation(reputation_name, value, source)
|
78
|
+
@user.with_reputation(:karma).where('karma > 10')
|
132
79
|
```
|
133
80
|
|
134
|
-
|
81
|
+
You can get source records that have evaluated the target record:
|
135
82
|
```ruby
|
136
|
-
|
137
|
-
reptuation_for(reputation_name)
|
138
|
-
|
139
|
-
# Returns the reputation rank of the reputation with the given name.
|
140
|
-
rank_for(reputation_name)
|
141
|
-
|
142
|
-
# Returns the normalized reputation value of the reputation with the given name. The normalization is computed using the following equation (assuming linear distribution):
|
143
|
-
# normalized_value = (x - min) / (max - min) if max - min is not 0
|
144
|
-
# normalized_value = 1 if max - min is 0
|
145
|
-
normalized_reptuation_for(reputation_name)
|
146
|
-
|
147
|
-
# Activates all reputations in the record. Active reputations are used when computing ranks or normalized reputation values.
|
148
|
-
activate_all_reputations
|
149
|
-
|
150
|
-
# Deactivates all reputations in the record. Inactive reputations are not used when computing ranks or normalized reputation values.
|
151
|
-
deactivate_all_reputations
|
152
|
-
|
153
|
-
# Checks if reputation is active.
|
154
|
-
reputations_activated?(reputation_name)
|
83
|
+
@question.evaluators_for(:votes) #=> [@user]
|
155
84
|
```
|
156
85
|
|
157
|
-
|
158
|
-
|
159
|
-
``` ruby
|
160
|
-
# Includes the specified reputation value for the given name.
|
161
|
-
ActiveRecord::Base.with_reputation(reputation_name, scope)
|
162
|
-
# For example:
|
163
|
-
User.with_reputation(:karma).where("karma > ?", 3).order("karma")
|
164
|
-
|
165
|
-
# Includes the specified normalized reputation value for the given name.
|
166
|
-
ActiveRecord::Base.with_normalized_reputation(reputation, scope)
|
167
|
-
# For example:
|
168
|
-
User.with_normalized_reputation(:karma).where("karma > ?" > 0.5).order("karma")
|
169
|
-
```
|
170
|
-
Note: Above query methods does not support calcualtion methods such as count, sum and etc yet.
|
171
|
-
|
86
|
+
You can get target records that have been evaluated by a given source record:
|
172
87
|
```ruby
|
173
|
-
|
174
|
-
ActiveRecord::Base.find_with_reputation(reputation_name, find_scope, options)
|
175
|
-
# For example:
|
176
|
-
User.find_with_reputation(:karma, :all, {:select => "id", :conditions => ["karma > ?", 3], :order => "karma"})
|
177
|
-
|
178
|
-
# Includes the specified normalized reputation value for the given name via a normal Active Record find query.
|
179
|
-
ActiveRecord::Base.find_with_normalized_reputation(reputation_name, find_options)
|
180
|
-
# For example:
|
181
|
-
User.find_with_normalized_reputation(:karma, :all, {:select => "id", :conditions => ["karma > ?", 0.5], :order => "karma"})
|
182
|
-
|
183
|
-
# Includes the specified reputation value for the given name via a normal Active Record count query.
|
184
|
-
ActiveRecord::Base.count_with_reputation(reputation_name, find_options)
|
185
|
-
|
186
|
-
# This method returns a SQL statement rather than a query result.
|
187
|
-
ActiveRecord::Base.find_with_reputation_sql(reputation_name, find_options)
|
88
|
+
Question.evaluated_by(:votes, @user) #=> [@question]
|
188
89
|
```
|
189
90
|
|
190
|
-
##
|
191
|
-
```ruby
|
192
|
-
# Returns all active record instances evaluated by a given source for a given reputation name.
|
193
|
-
ActiveRecord::Base.evaluated_by(reputation_name, source)
|
194
|
-
# For example:
|
195
|
-
Question.evaluated_by(:votes, @user)
|
196
|
-
```
|
197
|
-
|
198
|
-
## Advanced Topics
|
199
|
-
### Scope
|
200
|
-
Reputations can have different scopes to provide additional context.
|
91
|
+
## Documentation
|
201
92
|
|
202
|
-
|
93
|
+
Please refer [Wiki](https://github.com/twitter/activerecord-reputation-system/wiki) for available APIs.
|
203
94
|
|
204
|
-
|
205
|
-
```ruby
|
206
|
-
has_reputation :name,
|
207
|
-
...
|
208
|
-
:scopes => [:scope1, :scope2, ...]
|
209
|
-
```
|
210
|
-
Once scopes are defined, evaluations can be added in the context of defined scopes:
|
211
|
-
```ruby
|
212
|
-
add_evaluation(:reputation_name, evaluation_value, source, :scope)
|
213
|
-
```
|
214
|
-
Also, reputations can be accessed in the context of scopes:
|
215
|
-
```ruby
|
216
|
-
reptuation_for(:reputation_name, :scope)
|
217
|
-
```
|
218
|
-
To use a scoped reputation as a source in another reputation, try this:
|
219
|
-
```ruby
|
220
|
-
has_reputation :rep1,
|
221
|
-
:source => {:reputation => :rep2, :scope => :scope1}
|
222
|
-
...
|
223
|
-
has_reputation :rep2,
|
224
|
-
...
|
225
|
-
:scopes => [:scope1, :scope2, ...],
|
226
|
-
:source_of => {:reputation => :rep1, :defined_for_scope => [:scope1]}
|
227
|
-
```
|
228
|
-
To execute an Active Record query using a scoped reputation, try this:
|
229
|
-
```ruby
|
230
|
-
ActiveRecord::Base.find_with_reputation(:reputation_name, :scope, :find_options)
|
231
|
-
```
|
232
|
-
To find active records evaluated by a given source for a scoped reputation, try this:
|
233
|
-
```ruby
|
234
|
-
ActiveRecord::Base.evaluated_by(:reputation_name, source, :scope)
|
235
|
-
```
|
236
|
-
There are a few more helper methods available for scopes:
|
237
|
-
```ruby
|
238
|
-
# Allows you to add a scope dynamically.
|
239
|
-
add_scope_for(reputation_name, scope)
|
240
|
-
|
241
|
-
# Returns true if the reputation has scopes.
|
242
|
-
has_scopes?(reputation_name)
|
243
|
-
|
244
|
-
# Returns true if the reputation has a given scope.
|
245
|
-
has_scope?(reputation_name, scope)
|
246
|
-
```
|
247
|
-
|
248
|
-
### Performance
|
249
|
-
|
250
|
-
For applications with large data set, computation of reputation values can be expensive. Therefore, it is common to perform the computation asynchronously (in batch). If you wish to asynchronously compute reputation values, I strongly recommend you to use [collectiveidea's Delayed Job](https://github.com/collectiveidea/delayed_job). For example:
|
251
|
-
|
252
|
-
```ruby
|
253
|
-
class User < ActiveRecord
|
254
|
-
has_reputation :karma,
|
255
|
-
:source => :user,
|
256
|
-
:aggregated_by => :sum
|
95
|
+
## Authors
|
257
96
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
end
|
262
|
-
```
|
97
|
+
Katsuya Noguchi
|
98
|
+
* [http://twitter.com/kn](http://twitter.com/kn)
|
99
|
+
* [http://github.com/katsuyan](http://github.com/katsuyan)
|
263
100
|
|
264
|
-
|
101
|
+
## Contributors
|
265
102
|
|
266
|
-
|
103
|
+
1. [NARKOZ (Nihad Abbasov)](https://github.com/NARKOZ) - 4 commits
|
104
|
+
2. [elitheeli (Eli Fox-Epstein)](https://github.com/elitheeli) - 1 commit
|
105
|
+
3. [amrnt (Amr Tamimi)](https://github.com/amrnt) - 1 commit
|
267
106
|
|
268
|
-
##
|
107
|
+
## Related Links
|
269
108
|
|
270
|
-
|
109
|
+
* RailsCasts: http://railscasts.com/episodes/364-active-record-reputation-system
|
110
|
+
* Inspired by ["Building Web Reputation Systems" by Randy Farmer and Bryce Glass](http://shop.oreilly.com/product/9780596159801.do)
|
271
111
|
|
272
112
|
## Versioning
|
273
113
|
|
@@ -283,15 +123,6 @@ And constructed with the following guidelines:
|
|
283
123
|
|
284
124
|
For more information on semantic versioning, please visit http://semver.org/.
|
285
125
|
|
286
|
-
## Authors
|
287
|
-
|
288
|
-
* Katsuya Noguchi: http://github.com/katsuyan
|
289
|
-
* Inspired by ["Building Web Reputation Systems" by Randy Farmer and Bryce Glass](http://shop.oreilly.com/product/9780596159801.do)
|
290
|
-
|
291
|
-
## Related Links
|
292
|
-
|
293
|
-
* RailsCasts: http://railscasts.com/episodes/364-active-record-reputation-system
|
294
|
-
|
295
126
|
## License
|
296
127
|
|
297
128
|
Copyright 2012 Twitter, Inc.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'reputation_system'
|
data/lib/reputation_system.rb
CHANGED
@@ -18,12 +18,12 @@ require 'reputation_system/base'
|
|
18
18
|
require 'reputation_system/query_methods'
|
19
19
|
require 'reputation_system/finder_methods'
|
20
20
|
require 'reputation_system/query_builder'
|
21
|
-
require 'reputation_system/
|
21
|
+
require 'reputation_system/evaluation_methods'
|
22
22
|
require 'reputation_system/network'
|
23
|
-
require 'reputation_system/
|
24
|
-
require 'reputation_system/
|
25
|
-
require 'models/
|
26
|
-
require 'models/
|
27
|
-
require 'models/
|
23
|
+
require 'reputation_system/reputation_methods'
|
24
|
+
require 'reputation_system/scope_methods'
|
25
|
+
require 'reputation_system/models/evaluation'
|
26
|
+
require 'reputation_system/models/reputation'
|
27
|
+
require 'reputation_system/models/reputation_message'
|
28
28
|
|
29
29
|
ActiveRecord::Base.send(:include, ReputationSystem::Base)
|
@@ -40,7 +40,7 @@ module ReputationSystem
|
|
40
40
|
|
41
41
|
module ClassMethods
|
42
42
|
def has_reputation(reputation_name, options)
|
43
|
-
has_valid_input = reputation_name && options[:
|
43
|
+
has_valid_input = reputation_name && options[:source]
|
44
44
|
|
45
45
|
raise ArgumentError, "has_reputation method received invalid arguments." unless has_valid_input
|
46
46
|
# Overwrites reputation if the same reputation name is declared in the same model.
|
@@ -48,19 +48,29 @@ module ReputationSystem
|
|
48
48
|
ReputationSystem::Network.remove_reputation_def(name, reputation_name) if has_reputation_for?(reputation_name)
|
49
49
|
|
50
50
|
# If it is first time to be called
|
51
|
-
unless ancestors.include?(ReputationSystem::
|
52
|
-
has_many :reputations, :as => :target, :class_name => "
|
51
|
+
unless ancestors.include?(ReputationSystem::ReputationMethods)
|
52
|
+
has_many :reputations, :as => :target, :class_name => "ReputationSystem::Reputation", :dependent => :destroy do
|
53
|
+
def for(reputation_name)
|
54
|
+
self.where(:reputation_name => reputation_name)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
has_many :evaluations, :as => :target, :class_name => "ReputationSystem::Evaluation", :dependent => :destroy do
|
58
|
+
def for(reputation_name)
|
59
|
+
self.where(:reputation_name => reputation_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
53
63
|
include ReputationSystem::QueryBuilder
|
54
64
|
include ReputationSystem::QueryMethods
|
55
65
|
include ReputationSystem::FinderMethods
|
56
|
-
include ReputationSystem::
|
57
|
-
include ReputationSystem::
|
66
|
+
include ReputationSystem::ReputationMethods
|
67
|
+
include ReputationSystem::ScopeMethods
|
58
68
|
end
|
59
69
|
|
60
70
|
ReputationSystem::Network.add_reputation_def(name, reputation_name, options)
|
61
71
|
|
62
72
|
# evaluation related methods are defined only for primary reputations
|
63
|
-
include ReputationSystem::
|
73
|
+
include ReputationSystem::EvaluationMethods if ReputationSystem::Network.is_primary_reputation?(name, reputation_name) && !ancestors.include?(ReputationSystem::EvaluationMethods)
|
64
74
|
end
|
65
75
|
|
66
76
|
def has_reputation_for?(reputation_name)
|
@@ -15,7 +15,7 @@
|
|
15
15
|
##
|
16
16
|
|
17
17
|
module ReputationSystem
|
18
|
-
module
|
18
|
+
module EvaluationMethods
|
19
19
|
module ClassMethods
|
20
20
|
def evaluated_by(reputation_name, source, *args)
|
21
21
|
scope = args.first
|
@@ -33,13 +33,26 @@ module ReputationSystem
|
|
33
33
|
klass.extend ClassMethods
|
34
34
|
end
|
35
35
|
|
36
|
+
def has_evaluation?(reputation_name, source, *args)
|
37
|
+
scope = args.first
|
38
|
+
srn = ReputationSystem::Network.get_scoped_reputation_name(self.class.name, reputation_name, scope)
|
39
|
+
!!ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(srn, source, self)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def evaluators_for(reputation_name, *args)
|
44
|
+
scope = args.first
|
45
|
+
srn = ReputationSystem::Network.get_scoped_reputation_name(self.class.name, reputation_name, scope)
|
46
|
+
self.evaluations.for(srn).includes(:source).map(&:source)
|
47
|
+
end
|
48
|
+
|
36
49
|
def add_evaluation(reputation_name, value, source, *args)
|
37
50
|
scope = args.first
|
38
51
|
srn = ReputationSystem::Network.get_scoped_reputation_name(self.class.name, reputation_name, scope)
|
39
52
|
process = ReputationSystem::Network.get_reputation_def(self.class.name, srn)[:aggregated_by]
|
40
|
-
evaluation =
|
41
|
-
rep =
|
42
|
-
|
53
|
+
evaluation = ReputationSystem::Evaluation.create_evaluation(srn, value, source, self)
|
54
|
+
rep = ReputationSystem::Reputation.find_or_create_reputation(srn, self, process)
|
55
|
+
ReputationSystem::Reputation.update_reputation_value_with_new_source(rep, evaluation, 1, process)
|
43
56
|
end
|
44
57
|
|
45
58
|
def update_evaluation(reputation_name, value, source, *args)
|
@@ -48,13 +61,14 @@ module ReputationSystem
|
|
48
61
|
evaluation.value = value
|
49
62
|
evaluation.save!
|
50
63
|
process = ReputationSystem::Network.get_reputation_def(self.class.name, srn)[:aggregated_by]
|
51
|
-
rep =
|
52
|
-
|
64
|
+
rep = ReputationSystem::Reputation.find_by_reputation_name_and_target(srn, self)
|
65
|
+
newSize = rep.received_messages.size
|
66
|
+
ReputationSystem::Reputation.update_reputation_value_with_updated_source(rep, evaluation, oldValue, newSize, 1, process)
|
53
67
|
end
|
54
68
|
|
55
69
|
def add_or_update_evaluation(reputation_name, value, source, *args)
|
56
70
|
srn, evaluation = find_srn_and_evaluation(reputation_name, source, args.first)
|
57
|
-
if
|
71
|
+
if ReputationSystem::Evaluation.exists? :reputation_name => srn, :source_id => source.id, :source_type => source.class.name, :target_id => self.id, :target_type => self.class.name
|
58
72
|
self.update_evaluation(reputation_name, value, source, *args)
|
59
73
|
else
|
60
74
|
self.add_evaluation(reputation_name, value, source, *args)
|
@@ -63,7 +77,11 @@ module ReputationSystem
|
|
63
77
|
|
64
78
|
def delete_evaluation(reputation_name, source, *args)
|
65
79
|
srn, evaluation = find_srn_and_evaluation(reputation_name, source, args.first)
|
66
|
-
|
80
|
+
if evaluation
|
81
|
+
!!delete_evaluation_without_validation(srn, evaluation)
|
82
|
+
else
|
83
|
+
false
|
84
|
+
end
|
67
85
|
end
|
68
86
|
|
69
87
|
def delete_evaluation!(reputation_name, source, *args)
|
@@ -82,7 +100,7 @@ module ReputationSystem
|
|
82
100
|
protected
|
83
101
|
def find_srn_and_evaluation(reputation_name, source, scope)
|
84
102
|
srn = ReputationSystem::Network.get_scoped_reputation_name(self.class.name, reputation_name, scope)
|
85
|
-
evaluation =
|
103
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(srn, source, self)
|
86
104
|
return srn, evaluation
|
87
105
|
end
|
88
106
|
|
@@ -93,7 +111,7 @@ module ReputationSystem
|
|
93
111
|
end
|
94
112
|
|
95
113
|
def find_evaluation!(reputation_name, srn, source)
|
96
|
-
evaluation =
|
114
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(srn, source, self)
|
97
115
|
raise ArgumentError, "Given instance of #{source.class.name} has not evaluated #{reputation_name} of the instance of #{self.class.name} yet." unless evaluation
|
98
116
|
evaluation
|
99
117
|
end
|
@@ -102,15 +120,16 @@ module ReputationSystem
|
|
102
120
|
process = ReputationSystem::Network.get_reputation_def(self.class.name, srn)[:aggregated_by]
|
103
121
|
oldValue = evaluation.value
|
104
122
|
evaluation.value = process == :product ? 1 : 0
|
105
|
-
rep =
|
106
|
-
|
123
|
+
rep = ReputationSystem::Reputation.find_by_reputation_name_and_target(srn, self)
|
124
|
+
newSize = rep.received_messages.size - 1
|
125
|
+
ReputationSystem::Reputation.update_reputation_value_with_updated_source(rep, evaluation, oldValue, newSize, 1, process)
|
107
126
|
evaluation.destroy
|
108
127
|
end
|
109
128
|
|
110
129
|
def change_evaluation_value_by(reputation_name, value, source, *args)
|
111
130
|
scope = args.first
|
112
131
|
srn = ReputationSystem::Network.get_scoped_reputation_name(self.class.name, reputation_name, scope)
|
113
|
-
evaluation =
|
132
|
+
evaluation = ReputationSystem::Evaluation.find_by_reputation_name_and_source_and_target(srn, source, self)
|
114
133
|
if evaluation.nil?
|
115
134
|
self.add_evaluation(reputation_name, value, source, scope)
|
116
135
|
else
|