merit 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.rdoc +5 -0
- data/app/models/merit_action.rb +25 -23
- data/lib/generators/merit/templates/create_merit_actions.rb +1 -0
- data/lib/merit/controller_extensions.rb +3 -1
- metadata +21 -21
data/Gemfile
CHANGED
data/README.rdoc
CHANGED
@@ -107,6 +107,11 @@ You may also add badges/rank "by hand" from controller actions:
|
|
107
107
|
Badge.find(3).grant_to(current_user)
|
108
108
|
|
109
109
|
|
110
|
+
= Upgrade to 0.2.0
|
111
|
+
|
112
|
+
Added +had_errors+ boolean attribute to +merit_actions+ table.
|
113
|
+
|
114
|
+
|
110
115
|
= Test application
|
111
116
|
|
112
117
|
To run the test application inside this gem follow:
|
data/app/models/merit_action.rb
CHANGED
@@ -3,32 +3,34 @@ class MeritAction < ActiveRecord::Base
|
|
3
3
|
def check_badge_rules(defined_rules)
|
4
4
|
action_name = "#{target_model}\##{action_method}"
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
defined_rules[action_name].
|
9
|
-
rule
|
6
|
+
unless had_errors
|
7
|
+
# Check Badge rules
|
8
|
+
if defined_rules[action_name].present?
|
9
|
+
defined_rules[action_name].each do |rule|
|
10
|
+
rule.grant_or_delete_badge(self)
|
11
|
+
end
|
10
12
|
end
|
11
|
-
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
# Check Point rules
|
15
|
+
actions_to_point = MeritPointRules.new.actions_to_point
|
16
|
+
if actions_to_point[action_name].present?
|
17
|
+
point_rule = actions_to_point[action_name]
|
18
|
+
point_rule[:to].each do |to|
|
19
|
+
if to == :action_user
|
20
|
+
if !(target = User.find_by_id(user_id))
|
21
|
+
Rails.logger.warn "[merit] no user found to grant points"
|
22
|
+
return
|
23
|
+
end
|
24
|
+
else
|
25
|
+
begin
|
26
|
+
target = target_object.send(to)
|
27
|
+
rescue
|
28
|
+
Rails.logger.warn "[merit] No target_object found on check_badge_rules."
|
29
|
+
return
|
30
|
+
end
|
29
31
|
end
|
32
|
+
target.update_attribute(:points, target.points + point_rule[:score])
|
30
33
|
end
|
31
|
-
target.update_attribute(:points, target.points + point_rule[:score])
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
@@ -43,6 +45,6 @@ class MeritAction < ActiveRecord::Base
|
|
43
45
|
|
44
46
|
# Mark merit_action as processed
|
45
47
|
def processed!
|
46
|
-
self.update_attribute
|
48
|
+
self.update_attribute :processed, true
|
47
49
|
end
|
48
50
|
end
|
@@ -11,8 +11,9 @@ module Merit
|
|
11
11
|
if badge_rules.defined_rules[action].present? || point_rules.actions_to_point[action].present?
|
12
12
|
target_id = params[:id]
|
13
13
|
# TODO: target_object should be configurable (now it's singularized controller name)
|
14
|
+
target_object = instance_variable_get(:"@#{controller_name.singularize}")
|
14
15
|
unless target_id =~ /^[0-9]+$/ # id nil, or string (friendly_id)?
|
15
|
-
target_id =
|
16
|
+
target_id = target_object.try(:id)
|
16
17
|
end
|
17
18
|
|
18
19
|
# TODO: value relies on params[:value] on the controller, should be configurable
|
@@ -21,6 +22,7 @@ module Merit
|
|
21
22
|
:user_id => current_user.try(:id),
|
22
23
|
:action_method => action_name,
|
23
24
|
:action_value => value,
|
25
|
+
:had_errors => target_object.try(:errors).try(:present?),
|
24
26
|
:target_model => controller_name,
|
25
27
|
:target_id => target_id
|
26
28
|
)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: General reputation Rails engine.
|
15
15
|
email: tutecosta@gmail.com
|
@@ -18,30 +18,30 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- app/models/badge.rb
|
21
|
-
- app/models/merit_action.rb
|
22
21
|
- app/models/badges_sash.rb
|
22
|
+
- app/models/merit_action.rb
|
23
23
|
- app/models/sash.rb
|
24
|
-
- lib/
|
25
|
-
- lib/
|
26
|
-
- lib/merit/
|
27
|
-
- lib/merit/
|
28
|
-
- lib/merit/
|
29
|
-
- lib/merit/
|
30
|
-
- lib/merit/controller_extensions.rb
|
31
|
-
- lib/merit/rules_badge.rb
|
32
|
-
- lib/merit.rb
|
33
|
-
- lib/generators/merit/templates/merit_rank_rules.rb
|
24
|
+
- lib/generators/active_record/merit_generator.rb
|
25
|
+
- lib/generators/active_record/templates/add_fields_to_model.rb
|
26
|
+
- lib/generators/merit/install_generator.rb
|
27
|
+
- lib/generators/merit/merit_generator.rb
|
28
|
+
- lib/generators/merit/templates/create_badges.rb
|
29
|
+
- lib/generators/merit/templates/create_badges_sashes.rb
|
34
30
|
- lib/generators/merit/templates/create_merit_actions.rb
|
35
|
-
- lib/generators/merit/templates/merit_point_rules.rb
|
36
31
|
- lib/generators/merit/templates/create_sashes.rb
|
37
32
|
- lib/generators/merit/templates/merit.rb
|
38
|
-
- lib/generators/merit/templates/create_badges.rb
|
39
|
-
- lib/generators/merit/templates/create_badges_sashes.rb
|
40
33
|
- lib/generators/merit/templates/merit_badge_rules.rb
|
41
|
-
- lib/generators/merit/
|
42
|
-
- lib/generators/merit/
|
43
|
-
- lib/
|
44
|
-
- lib/
|
34
|
+
- lib/generators/merit/templates/merit_point_rules.rb
|
35
|
+
- lib/generators/merit/templates/merit_rank_rules.rb
|
36
|
+
- lib/merit/controller_extensions.rb
|
37
|
+
- lib/merit/core_extensions.rb
|
38
|
+
- lib/merit/model_additions.rb
|
39
|
+
- lib/merit/railtie.rb
|
40
|
+
- lib/merit/rule.rb
|
41
|
+
- lib/merit/rules_badge.rb
|
42
|
+
- lib/merit/rules_points.rb
|
43
|
+
- lib/merit/rules_rank.rb
|
44
|
+
- lib/merit.rb
|
45
45
|
- MIT-LICENSE
|
46
46
|
- Rakefile
|
47
47
|
- Gemfile
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
68
|
rubyforge_project:
|
69
|
-
rubygems_version: 1.8.
|
69
|
+
rubygems_version: 1.8.11
|
70
70
|
signing_key:
|
71
71
|
specification_version: 3
|
72
72
|
summary: General reputation Rails engine.
|