Commit 2a9421e8bbce852d98c7d20590429bdaacf45d40
1 parent
a49ad7f9
Exists in
master
and in
1 other branch
Delegate Merit::Badge to GamificationPlugin::Badge
Showing
4 changed files
with
18 additions
and
7 deletions
Show diff stats
lib/ext/environment.rb
| ... | ... | @@ -2,6 +2,6 @@ require_dependency 'environment' |
| 2 | 2 | |
| 3 | 3 | class Environment |
| 4 | 4 | |
| 5 | - has_many :gamification_plugin_badges, :class_name => 'GamificationPlugin::Badge', :foreign_key => 'owner_id' | |
| 5 | + has_many :gamification_plugin_badges, :class_name => 'GamificationPlugin::Badge', :foreign_key => 'owner_id', :source => :owner | |
| 6 | 6 | |
| 7 | 7 | end | ... | ... |
lib/merit/badge_rules.rb
| ... | ... | @@ -41,13 +41,8 @@ module Merit |
| 41 | 41 | def initialize(environment=nil) |
| 42 | 42 | return if environment.nil? |
| 43 | 43 | @environment = environment |
| 44 | - # FIXME avoid this | |
| 45 | - Merit::Badge.all.each { |badge| badge.destroy } | |
| 46 | - | |
| 47 | - GamificationPlugin::Badge.all.each do |badge| | |
| 48 | - # FIXME avoid this | |
| 49 | - Merit::Badge.create!(:name => badge.name, :id => badge.id, :level => badge.level) # FIXME conflict with multitenancy? | |
| 50 | 44 | |
| 45 | + environment.gamification_plugin_badges.all.each do |badge| | |
| 51 | 46 | setting = AVAILABLE_RULES[badge.name.to_sym] |
| 52 | 47 | grant_on setting[:action], :badge => badge.name, :level => badge.level do |source| |
| 53 | 48 | setting[:value].call(source) >= (badge.custom_fields || {}).fetch(:threshold, setting[:default_threshold]) | ... | ... |
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +require_dependency 'merit/badge' | |
| 2 | + | |
| 3 | +module Merit | |
| 4 | + | |
| 5 | + # Delegate find methods to GamificationPlugin::Badge | |
| 6 | + class Badge | |
| 7 | + class << self | |
| 8 | + [:find_by_name_and_level, :find].each do |method| | |
| 9 | + delegate method, :to => 'GamificationPlugin::Badge' | |
| 10 | + end | |
| 11 | + end | |
| 12 | + end | |
| 13 | + | |
| 14 | +end | ... | ... |
lib/merit_ext.rb