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 CHANGED
@@ -1,10 +1,2 @@
1
1
  source "http://rubygems.org"
2
-
3
2
  gemspec
4
-
5
- group :development, :test do
6
- gem "rails", "~> 3.0.10"
7
- gem "sqlite3"
8
- gem "haml"
9
- gem "capybara"
10
- end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- merit (0.4.0)
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.2.2)
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
- * [A4bandas media](https://github.com/a4bandas)
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)
@@ -1,5 +1,9 @@
1
1
  # Upgrading
2
2
 
3
+ ## to 0.5.0
4
+
5
+ Add <tt>log:string</tt> column to <tt>merit_actions</tt> table.
6
+
3
7
  ## to 0.4.0
4
8
 
5
9
  Rankings are now integer attributes (<tt>level</tt>), they are not badges
@@ -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
- sash.add_badge(id) unless sash.badge_ids.include?(id)
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
- sash.rm_badge(id) if sash.badge_ids.include?(id)
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
@@ -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
@@ -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
@@ -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
- if sash = sash_to_badge(action)
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
 
@@ -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 = "General reputation Rails engine."
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.4.2"
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
@@ -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 => 20120309191345) do
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.2
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-10 00:00:00.000000000 Z
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: &70244741311580 !ruby/object:Gem::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: *70244741311580
24
+ version_requirements: *70296877186780
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rails
27
- requirement: &70244741310660 !ruby/object:Gem::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: '0'
32
+ version: 3.0.10
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70244741310660
35
+ version_requirements: *70296877186260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70244740748260 !ruby/object:Gem::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: *70244740748260
46
+ version_requirements: *70296877185840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: haml
49
- requirement: &70244740747620 !ruby/object:Gem::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: *70244740747620
57
+ version_requirements: *70296879096200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: capybara
60
- requirement: &70244740746780 !ruby/object:Gem::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: *70244740746780
69
- description: General reputation Rails engine.
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: []
@@ -1,7 +0,0 @@
1
- require 'merit'
2
- require 'rails'
3
-
4
- module Merit
5
- class Engine < Rails::Engine
6
- end
7
- end