Commit 3520fc1a6b506579c485f8f2ad27103b1ba07bc4
1 parent
4cb40a31
Exists in
master
and in
1 other branch
Score for a community where an article is created
Showing
1 changed file
with
18 additions
and
2 deletions
Show diff stats
lib/merit/point_rules.rb
| ... | ... | @@ -17,7 +17,16 @@ module Merit |
| 17 | 17 | :to => :author, |
| 18 | 18 | :value => 1, |
| 19 | 19 | :description => _('Point weight for article author'), |
| 20 | - :default_weight => 50 | |
| 20 | + :default_weight => 500 | |
| 21 | + }, | |
| 22 | + :article_community => { | |
| 23 | + :action => 'article#create', | |
| 24 | + :undo_action => 'article#destroy', | |
| 25 | + :to => :profile, | |
| 26 | + :value => 1, | |
| 27 | + :description => _('Point weight for article community'), | |
| 28 | + :default_weight => 500, | |
| 29 | + :condition => lambda {|target| target.profile.community? } | |
| 21 | 30 | }, |
| 22 | 31 | :vote_voteable_author => { |
| 23 | 32 | :action => 'vote#create', |
| ... | ... | @@ -50,13 +59,20 @@ module Merit |
| 50 | 59 | weight(category) * value |
| 51 | 60 | end |
| 52 | 61 | |
| 62 | + def condition(setting, target) | |
| 63 | + condition = setting[:condition] | |
| 64 | + condition.present? ? condition.call(target) : true | |
| 65 | + end | |
| 66 | + | |
| 53 | 67 | def initialize(environment=nil) |
| 54 | 68 | return if environment.nil? |
| 55 | 69 | @environment = environment |
| 56 | 70 | |
| 57 | 71 | AVAILABLE_RULES.each do |category, setting| |
| 58 | 72 | [setting[:action], setting[:undo_action]].compact.zip([1, -1]).each do |action, signal| |
| 59 | - score lambda {|target| signal * calculate_score(target, category, setting[:value])}, :on => action, :to => setting[:to], :category => category | |
| 73 | + score lambda {|target| signal * calculate_score(target, category, setting[:value])}, :on => action, :to => setting[:to], :category => category do |target| | |
| 74 | + condition(setting, target) | |
| 75 | + end | |
| 60 | 76 | end |
| 61 | 77 | end |
| 62 | 78 | end | ... | ... |