Commit 564beb33f68e00f9a8fc36021b77f6c4bc6eccbe
1 parent
0ee65a55
Exists in
master
and in
1 other branch
Improve point rules types and categorization setup
Showing
2 changed files
with
9 additions
and
6 deletions
Show diff stats
lib/gamification_plugin.rb
... | ... | @@ -24,12 +24,6 @@ class GamificationPlugin < Noosfero::Plugin |
24 | 24 | Merit::AppBadgeRules.clear |
25 | 25 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) |
26 | 26 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) |
27 | - #FIXME We have to make a refactor of this code to avoid database data dependendy | |
28 | - Merit::PointRules::AVAILABLE_RULES.map do |rule_name, rule| | |
29 | - point_type = GamificationPlugin::PointsType.find_by_name rule_name | |
30 | - point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? | |
31 | - GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, weight: rule[:default_weight] | |
32 | - end | |
33 | 27 | end |
34 | 28 | |
35 | 29 | def application_controller_filters |
... | ... | @@ -75,6 +69,7 @@ class GamificationPlugin < Noosfero::Plugin |
75 | 69 | config.current_user_method = 'current_person' |
76 | 70 | config.add_observer 'Merit::PointTrackObserver' |
77 | 71 | config.add_observer 'Merit::RankObserver' |
72 | + Merit::PointRules.setup | |
78 | 73 | end |
79 | 74 | |
80 | 75 | require_dependency 'merit_ext' | ... | ... |
lib/merit/point_rules.rb
... | ... | @@ -147,6 +147,14 @@ module Merit |
147 | 147 | end |
148 | 148 | end |
149 | 149 | |
150 | + def self.setup | |
151 | + AVAILABLE_RULES.map do |rule_name, rule| | |
152 | + point_type = GamificationPlugin::PointsType.find_by_name rule_name | |
153 | + point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? | |
154 | + GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, weight: rule[:default_weight] | |
155 | + end | |
156 | + end | |
157 | + | |
150 | 158 | def initialize(environment=nil) |
151 | 159 | return if environment.nil? |
152 | 160 | @environment = environment | ... | ... |