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 CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "rails", "3.0.10"
3
+ gem "rails", "~> 3.0.10"
4
4
  gem "sqlite3"
5
5
  gem "haml"
6
6
  gem "capybara"
@@ -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:
@@ -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
- # Check Badge rules
7
- if defined_rules[action_name].present?
8
- defined_rules[action_name].each do |rule|
9
- rule.grant_or_delete_badge(self)
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
- # Check Point rules
14
- actions_to_point = MeritPointRules.new.actions_to_point
15
- if actions_to_point[action_name].present?
16
- point_rule = actions_to_point[action_name]
17
- point_rule[:to].each do |to|
18
- if to == :action_user
19
- if !(target = User.find_by_id(user_id))
20
- Rails.logger.warn "[merit] no user found to grant points"
21
- return
22
- end
23
- else
24
- begin
25
- target = target_object.send(to)
26
- rescue
27
- Rails.logger.warn "[merit] No target_object found on check_badge_rules."
28
- return
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(:processed, true)
48
+ self.update_attribute :processed, true
47
49
  end
48
50
  end
@@ -4,6 +4,7 @@ class CreateMeritActions < ActiveRecord::Migration
4
4
  t.integer :user_id # source
5
5
  t.string :action_method
6
6
  t.integer :action_value
7
+ t.boolean :had_errors
7
8
  t.string :target_model
8
9
  t.integer :target_id
9
10
  t.boolean :processed, :default => false
@@ -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 = instance_variable_get(:"@#{controller_name.singularize}").try(: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.1.3
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: 2011-11-25 00:00:00.000000000 Z
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/merit/rules_points.rb
25
- - lib/merit/rule.rb
26
- - lib/merit/railtie.rb
27
- - lib/merit/core_extensions.rb
28
- - lib/merit/model_additions.rb
29
- - lib/merit/rules_rank.rb
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/merit_generator.rb
42
- - lib/generators/merit/install_generator.rb
43
- - lib/generators/active_record/templates/add_fields_to_model.rb
44
- - lib/generators/active_record/merit_generator.rb
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.5
69
+ rubygems_version: 1.8.11
70
70
  signing_key:
71
71
  specification_version: 3
72
72
  summary: General reputation Rails engine.