merit 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -8
- data/Gemfile.lock +2 -2
- data/README.md +5 -10
- data/UPGRADING.md +4 -0
- data/app/models/badge.rb +12 -2
- data/app/models/merit_action.rb +5 -0
- data/lib/generators/active_record/templates/create_merit_actions.rb +1 -0
- data/lib/merit/rule.rb +12 -7
- data/merit.gemspec +4 -5
- data/test/dummy/db/migrate/20120318022217_create_merit_actions.rb +2 -1
- data/test/dummy/db/schema.rb +3 -1
- metadata +17 -17
- data/lib/merit/railtie.rb +0 -7
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
merit (0.4.
|
4
|
+
merit (0.4.2)
|
5
5
|
ambry
|
6
6
|
|
7
7
|
GEM
|
@@ -80,7 +80,7 @@ GEM
|
|
80
80
|
rake (>= 0.8.7)
|
81
81
|
rdoc (~> 3.4)
|
82
82
|
thor (~> 0.14.4)
|
83
|
-
rake (0.9.
|
83
|
+
rake (0.9.3.beta.1)
|
84
84
|
rdoc (3.12)
|
85
85
|
json (~> 1.4)
|
86
86
|
rubyzip (0.9.6.1)
|
data/README.md
CHANGED
@@ -112,17 +112,11 @@ Check for rules on a rake task executed in background like:
|
|
112
112
|
|
113
113
|
---
|
114
114
|
|
115
|
-
# MongoMapper support (experimental)
|
116
|
-
|
117
|
-
You may use <tt>merit</tt> with <tt>mongo_mapper</tt> ORM by calling
|
118
|
-
<tt>rails g merit MODEL_NAME --orm mongo_mapper</tt> in the third step of the
|
119
|
-
installation, and configuring <tt>config.orm = :mongo_mapper</tt> in
|
120
|
-
<tt>config/initializers/merit.rb</tt>.
|
121
|
-
|
122
|
-
---
|
123
|
-
|
124
115
|
# To-do list
|
125
116
|
|
117
|
+
* Abstract User (rule.rb#51 for instance) into a Merit option.
|
118
|
+
* What happens if 'class MeritPointRules; include Merit::PointRules' is changed by 'module Merit::PointRules'?
|
119
|
+
* Should namespace app/models into Merit module.
|
126
120
|
* rescue ActiveRecord::... should depend on ORM used (MongoMapper?)
|
127
121
|
* Why 1.8.7 tests are not passing?
|
128
122
|
* :value parameter (for star voting for example) should be configurable
|
@@ -133,6 +127,7 @@ installation, and configuring <tt>config.orm = :mongo_mapper</tt> in
|
|
133
127
|
|
134
128
|
# Contributors
|
135
129
|
|
136
|
-
* [
|
130
|
+
* [Tute Costa](https://github.com/tute)
|
137
131
|
* [Juan Schwindt](https://github.com/jschwindt)
|
138
132
|
* [Eric Knudtson](https://github.com/ek)
|
133
|
+
* [A4bandas media](https://github.com/a4bandas)
|
data/UPGRADING.md
CHANGED
data/app/models/badge.rb
CHANGED
@@ -27,13 +27,23 @@ class Badge
|
|
27
27
|
def grant_to(object_or_sash)
|
28
28
|
object_or_sash.create_sash_if_none unless object_or_sash.kind_of?(Sash)
|
29
29
|
sash = object_or_sash.respond_to?(:sash) ? object_or_sash.sash : object_or_sash
|
30
|
-
|
30
|
+
if sash.badge_ids.include?(id)
|
31
|
+
return false
|
32
|
+
else
|
33
|
+
sash.add_badge(id)
|
34
|
+
return true
|
35
|
+
end
|
31
36
|
end
|
32
37
|
|
33
38
|
# Take out badge from sash
|
34
39
|
def delete_from(object_or_sash)
|
35
40
|
object_or_sash.create_sash_if_none unless object_or_sash.kind_of?(Sash)
|
36
41
|
sash = object_or_sash.respond_to?(:sash) ? object_or_sash.sash : object_or_sash
|
37
|
-
|
42
|
+
if sash.badge_ids.include?(id)
|
43
|
+
sash.rm_badge(id)
|
44
|
+
return true
|
45
|
+
else
|
46
|
+
return false
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
data/app/models/merit_action.rb
CHANGED
@@ -32,6 +32,7 @@ class MeritAction
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
target.update_attribute(:points, target.points + point_rule[:score])
|
35
|
+
log!("points_granted:#{point_rule[:score]}")
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -46,6 +47,10 @@ class MeritAction
|
|
46
47
|
klass.singularize.camelize.constantize.find_by_id(target_id)
|
47
48
|
end
|
48
49
|
|
50
|
+
def log!(str)
|
51
|
+
self.update_attribute :log, "#{self.log}#{str}|"
|
52
|
+
end
|
53
|
+
|
49
54
|
# Mark merit_action as processed
|
50
55
|
def processed!
|
51
56
|
self.update_attribute :processed, true
|
data/lib/merit/rule.rb
CHANGED
@@ -28,14 +28,19 @@ module Merit
|
|
28
28
|
# Grant badge if rule applies. If it doesn't, and the badge is temporary,
|
29
29
|
# then remove it.
|
30
30
|
def grant_or_delete_badge(action)
|
31
|
-
|
32
|
-
if applies? action.target_object(model_name)
|
33
|
-
badge.grant_to sash
|
34
|
-
elsif temporary?
|
35
|
-
badge.delete_from sash
|
36
|
-
end
|
37
|
-
else
|
31
|
+
unless (sash = sash_to_badge(action))
|
38
32
|
Rails.logger.warn "[merit] no sash found on Rule#grant_or_delete_badge"
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
if applies? action.target_object(model_name)
|
37
|
+
if badge.grant_to(sash)
|
38
|
+
action.log!("badge_granted:#{badge.name}")
|
39
|
+
end
|
40
|
+
elsif temporary?
|
41
|
+
if badge.delete_from(sash)
|
42
|
+
action.log!("badge_removed:#{badge.name}")
|
43
|
+
end
|
39
44
|
end
|
40
45
|
end
|
41
46
|
|
data/merit.gemspec
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
# Provide a simple gemspec so you can easily use your enginex
|
2
|
-
# project in your rails apps through git.
|
3
1
|
Gem::Specification.new do |s|
|
4
2
|
s.name = "merit"
|
5
3
|
s.summary = "General reputation Rails engine."
|
6
|
-
s.description = "
|
4
|
+
s.description = "Manage badges, points and rankings (reputation) of resources in a Rails application."
|
5
|
+
s.homepage = "http://github.com/tute/merit"
|
7
6
|
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
|
8
|
-
s.version = "0.
|
7
|
+
s.version = "0.5.0"
|
9
8
|
s.authors = ["Tute Costa"]
|
10
9
|
s.email = 'tutecosta@gmail.com'
|
11
10
|
s.add_dependency 'ambry'
|
12
|
-
s.add_development_dependency 'rails'
|
11
|
+
s.add_development_dependency 'rails', '~> 3.0.10'
|
13
12
|
s.add_development_dependency 'sqlite3'
|
14
13
|
s.add_development_dependency 'haml'
|
15
14
|
s.add_development_dependency 'capybara'
|
@@ -8,6 +8,7 @@ class CreateMeritActions < ActiveRecord::Migration
|
|
8
8
|
t.string :target_model
|
9
9
|
t.integer :target_id
|
10
10
|
t.boolean :processed, :default => false
|
11
|
+
t.string :log, :default => nil
|
11
12
|
t.timestamps
|
12
13
|
end
|
13
14
|
end
|
@@ -15,4 +16,4 @@ class CreateMeritActions < ActiveRecord::Migration
|
|
15
16
|
def self.down
|
16
17
|
drop_table :merit_actions
|
17
18
|
end
|
18
|
-
end
|
19
|
+
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20120318022220) do
|
15
15
|
|
16
16
|
create_table "badges_sashes", :id => false, :force => true do |t|
|
17
17
|
t.integer "badge_id"
|
@@ -41,6 +41,7 @@ ActiveRecord::Schema.define(:version => 20120309191345) do
|
|
41
41
|
t.string "target_model"
|
42
42
|
t.integer "target_id"
|
43
43
|
t.boolean "processed", :default => false
|
44
|
+
t.string "log"
|
44
45
|
t.datetime "created_at"
|
45
46
|
t.datetime "updated_at"
|
46
47
|
end
|
@@ -56,6 +57,7 @@ ActiveRecord::Schema.define(:version => 20120309191345) do
|
|
56
57
|
t.datetime "updated_at"
|
57
58
|
t.integer "sash_id"
|
58
59
|
t.integer "points", :default => 0
|
60
|
+
t.integer "level", :default => 0
|
59
61
|
end
|
60
62
|
|
61
63
|
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.5.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-04-
|
12
|
+
date: 2012-04-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ambry
|
16
|
-
requirement: &
|
16
|
+
requirement: &70296877186780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70296877186780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rails
|
27
|
-
requirement: &
|
27
|
+
requirement: &70296877186260 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
|
-
- -
|
30
|
+
- - ~>
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version:
|
32
|
+
version: 3.0.10
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70296877186260
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70296877185840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70296877185840
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: haml
|
49
|
-
requirement: &
|
49
|
+
requirement: &70296879096200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70296879096200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: capybara
|
60
|
-
requirement: &
|
60
|
+
requirement: &70296879094600 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,8 +65,9 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
69
|
-
description:
|
68
|
+
version_requirements: *70296879094600
|
69
|
+
description: Manage badges, points and rankings (reputation) of resources in a Rails
|
70
|
+
application.
|
70
71
|
email: tutecosta@gmail.com
|
71
72
|
executables: []
|
72
73
|
extensions: []
|
@@ -99,7 +100,6 @@ files:
|
|
99
100
|
- lib/merit/models/active_record/sash.rb
|
100
101
|
- lib/merit/models/mongo_mapper/merit_action.rb
|
101
102
|
- lib/merit/models/mongo_mapper/sash.rb
|
102
|
-
- lib/merit/railtie.rb
|
103
103
|
- lib/merit/rule.rb
|
104
104
|
- lib/merit/rules_badge.rb
|
105
105
|
- lib/merit/rules_points.rb
|
@@ -169,7 +169,7 @@ files:
|
|
169
169
|
- test/merit_unit_test.rb
|
170
170
|
- test/support/integration_case.rb
|
171
171
|
- test/test_helper.rb
|
172
|
-
homepage:
|
172
|
+
homepage: http://github.com/tute/merit
|
173
173
|
licenses: []
|
174
174
|
post_install_message:
|
175
175
|
rdoc_options: []
|