merit 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +8 -4
- data/UPGRADING.md +18 -1
- data/app/models/badge.rb +14 -5
- data/lib/merit/rule.rb +2 -4
- data/merit.gemspec +1 -1
- data/test/dummy/app/models/merit/badge_rules.rb +1 -1
- data/test/merit_unit_test.rb +12 -0
- metadata +59 -19
data/Gemfile.lock
CHANGED
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!).
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
# Upgrading
|
2
2
|
|
3
|
-
## to 0.
|
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:
|
data/app/models/badge.rb
CHANGED
@@ -12,8 +12,8 @@ class Badge
|
|
12
12
|
|
13
13
|
filters do
|
14
14
|
def find_by_id(ids)
|
15
|
-
ids =
|
16
|
-
find{|b| ids.include? b
|
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
|
-
|
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
|
-
|
31
|
-
|
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
|
data/lib/merit/rule.rb
CHANGED
@@ -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
|
-
|
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
|
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
|
data/merit.gemspec
CHANGED
@@ -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.
|
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
|
-
|
26
|
+
true
|
27
27
|
end
|
28
28
|
|
29
29
|
# Example rule for multiple badge granting
|
data/test/merit_unit_test.rb
CHANGED
@@ -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.
|
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-
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
320
|
+
rubygems_version: 1.8.23
|
281
321
|
signing_key:
|
282
322
|
specification_version: 3
|
283
323
|
summary: General reputation Rails engine.
|