merit 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,7 +70,7 @@ GEM
70
70
  activemodel (~> 3.1)
71
71
  mongo (~> 1.3)
72
72
  tzinfo (~> 0.3.22)
73
- multi_json (1.3.2)
73
+ multi_json (1.3.6)
74
74
  nokogiri (1.5.2)
75
75
  polyglot (0.3.3)
76
76
  rack (1.4.1)
data/README.md CHANGED
@@ -83,14 +83,20 @@ score 10, :on => [
83
83
  'users#update'
84
84
  ]
85
85
 
86
- score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
87
-
88
86
  score 20, :on => [
89
87
  'comments#create',
90
88
  'photos#create'
91
89
  ]
92
90
  ```
93
91
 
92
+ `:to` method(s) work as in badge rules: they are sent to the target_object.
93
+ In the following example, after a review gets created both `review.reviewer`
94
+ and `review.reviewed` are granted 15 points:
95
+
96
+ ```ruby
97
+ score 15, :on => 'reviews#create', :to => [:reviewer, :reviewed]
98
+ ```
99
+
94
100
  ---
95
101
 
96
102
  # Defining rank rules
@@ -133,7 +139,6 @@ end
133
139
 
134
140
  # To-do list
135
141
 
136
- * `Badge#grant_to` should accept a second `multiple` parameter
137
142
  * Can infer params[:id] = instance_variable.id in create actions, for having
138
143
  the object in the rule method parameter, so we don't need it in controllers.
139
144
  * add an error handler for inexistent badges.
@@ -141,7 +146,6 @@ end
141
146
  * Abstract User (rule.rb#51 for instance) into a Merit option.
142
147
  * Should namespace app/models into Merit module.
143
148
  * rescue ActiveRecord::... should depend on ORM used
144
- * Why 1.8.7 tests are not passing?
145
149
  * :value parameter (for star voting for example) should be configurable
146
150
  (depends on params[:value] on the controller).
147
151
  * Make fixtures for integration testing (now creating objects on test file!).
@@ -1,6 +1,23 @@
1
1
  # Upgrading
2
2
 
3
- ## to 0.6.1
3
+ ## to 0.9.0
4
+
5
+ Adds `allow_multiple` boolean option to `Badge#grant_to` (defaults to
6
+ `false`). If you used this method to grant a badge it will now grant only if
7
+ resource doesn't have the badge.
8
+
9
+ Use `grant_to resource, :allow_multiple => true` where needed.
10
+
11
+ ## to 0.8.0
12
+
13
+ No changes needed. Adds Mongoid support.
14
+
15
+ ## to 0.7.0
16
+
17
+ No changes needed. Adds `:multiple` boolean option to `grant_on` to grant
18
+ badge multiple times.
19
+
20
+ ## to 0.6.0
4
21
 
5
22
  <tt>MeritBadgeRules</tt>, <tt>MeritPointRules</tt> and <tt>MeritRankRules</tt>
6
23
  are now namespaced into Merit module. Move and change:
@@ -12,8 +12,8 @@ class Badge
12
12
 
13
13
  filters do
14
14
  def find_by_id(ids)
15
- ids = ids.kind_of?(Array) ? ids : [ids]
16
- find{|b| ids.include? b.id }
15
+ ids = Array.wrap(ids)
16
+ find{|b| ids.include? b[:id] }
17
17
  end
18
18
  def by_name(name)
19
19
  find{|b| b.name == name.to_s }
@@ -24,11 +24,20 @@ class Badge
24
24
  end
25
25
 
26
26
  # Grant badge to sash
27
- def grant_to(object_or_sash)
27
+ # Accepts :allow_multiple boolean option, defaults to false
28
+ def grant_to(object_or_sash, *args)
28
29
  object_or_sash.create_sash_if_none unless object_or_sash.kind_of?(Sash)
29
30
  sash = object_or_sash.respond_to?(:sash) ? object_or_sash.sash : object_or_sash
30
- sash.add_badge(id)
31
- return true
31
+
32
+ options = args.extract_options!
33
+ options[:allow_multiple] ||= false
34
+
35
+ if !sash.badge_ids.include?(id) || options[:allow_multiple]
36
+ sash.add_badge(id)
37
+ return true
38
+ else
39
+ return false
40
+ end
32
41
  end
33
42
 
34
43
  # Take out badge from sash
@@ -17,12 +17,11 @@ module Merit
17
17
  Rails.logger.warn "[merit] no target_obj found on Rule#applies?. MeritAction: #{action.inspect}"
18
18
  return false
19
19
  end
20
- when 0 # evaluates to boolean
20
+ else # evaluates to boolean. block.arity returns 0 in Ruby 1.9.3 and -1 in Ruby 1.8.7
21
21
  return block.call
22
22
  end
23
23
  end
24
24
 
25
- def multiple?; self.multiple; end
26
25
  def temporary?; self.temporary; end
27
26
 
28
27
  # Grant badge if rule applies. If it doesn't, and the badge is temporary,
@@ -34,8 +33,7 @@ module Merit
34
33
  end
35
34
 
36
35
  if applies? action.target_object(model_name)
37
- if !sash.badge_ids.include?(badge.id) || multiple?
38
- badge.grant_to(sash)
36
+ if badge.grant_to(sash, :allow_multiple => self.multiple)
39
37
  to_action_user = (to.to_sym == :action_user ? '_to_action_user' : '')
40
38
  action.log!("badge_granted#{to_action_user}:#{badge.id}")
41
39
  end
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
5
5
  s.homepage = "http://github.com/tute/merit"
6
6
  s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
7
- s.version = "0.8.1"
7
+ s.version = "0.9.0"
8
8
  s.authors = ["Tute Costa"]
9
9
  s.email = 'tutecosta@gmail.com'
10
10
  s.add_dependency 'ambry', '~> 0.3.0'
@@ -23,7 +23,7 @@ module Merit
23
23
  # Should be "current_user" after registration for badge to be granted.
24
24
  # Example rule with block with no parameters
25
25
  grant_on 'users#create', :badge => 'just-registered', :to => :itself do
26
- Date.today > 1.year.ago.to_date
26
+ true
27
27
  end
28
28
 
29
29
  # Example rule for multiple badge granting
@@ -22,4 +22,16 @@ class MeritUnitTest < ActiveSupport::TestCase
22
22
  badge_sash.badge_id = 99
23
23
  assert_equal Badge.find(99), badge_sash.badge
24
24
  end
25
+
26
+ test "Badge#grant_to allow_multiple option" do
27
+ badge = Badge.create(:id => 99, :name => 'test-badge')
28
+ sash = Sash.create(:id => 99)
29
+ assert_equal 0, sash.badge_ids.count
30
+ badge.grant_to sash
31
+ assert_equal 1, sash.reload.badge_ids.count
32
+ badge.grant_to sash
33
+ assert_equal 1, sash.reload.badge_ids.count
34
+ badge.grant_to sash, :allow_multiple => true
35
+ assert_equal 2, sash.reload.badge_ids.count
36
+ end
25
37
  end
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.8.1
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-27 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ambry
16
- requirement: &70334081390280 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: 0.3.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70334081390280
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.3.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rails
27
- requirement: &70334081389800 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ~>
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: 3.2.3
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70334081389800
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.3
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sqlite3
38
- requirement: &70334081409880 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70334081409880
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: haml
49
- requirement: &70334081409420 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70334081409420
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: capybara
60
- requirement: &70334081409000 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70334081409000
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: simplecov
71
- requirement: &70334081408580 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70334081408580
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: bson_ext
82
- requirement: &70334081408160 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70334081408160
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: mongoid
93
- requirement: &70334081407660 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ~>
@@ -98,7 +133,12 @@ dependencies:
98
133
  version: 2.0.0
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70334081407660
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 2.0.0
102
142
  description: Manage badges, points and rankings (reputation) of resources in a Rails
103
143
  application.
104
144
  email: tutecosta@gmail.com
@@ -277,7 +317,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
277
317
  version: '0'
278
318
  requirements: []
279
319
  rubyforge_project:
280
- rubygems_version: 1.8.11
320
+ rubygems_version: 1.8.23
281
321
  signing_key:
282
322
  specification_version: 3
283
323
  summary: General reputation Rails engine.