merit 3.0.3 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -9
- data/NEWS.md +25 -0
- data/README.md +29 -10
- data/app/models/merit/badge.rb +1 -9
- data/lib/merit/{rules_badge_methods.rb → badge_rules_methods.rb} +0 -0
- data/lib/merit/base_target_finder.rb +1 -6
- data/lib/merit/{model_additions.rb → class_methods.rb} +0 -11
- data/lib/merit/controller_extensions.rb +4 -22
- data/lib/{generators → merit/generators}/active_record/install_generator.rb +8 -8
- data/lib/{generators → merit/generators}/active_record/merit_generator.rb +4 -4
- data/lib/{generators → merit/generators}/active_record/remove_generator.rb +5 -5
- data/lib/{generators/active_record/templates/add_merit_fields_to_model.rb → merit/generators/active_record/templates/add_merit_fields_to_model.erb} +0 -0
- data/lib/{generators/active_record/templates/create_badges_sashes.rb → merit/generators/active_record/templates/create_badges_sashes.erb} +0 -0
- data/lib/{generators/active_record/templates/create_merit_actions.rb → merit/generators/active_record/templates/create_merit_actions.erb} +2 -0
- data/lib/{generators/active_record/templates/create_merit_activity_logs.rb → merit/generators/active_record/templates/create_merit_activity_logs.erb} +0 -0
- data/lib/{generators/active_record/templates/create_sashes.rb → merit/generators/active_record/templates/create_sashes.erb} +0 -0
- data/lib/{generators/active_record/templates/create_scores_and_points.rb → merit/generators/active_record/templates/create_scores_and_points.erb} +1 -1
- data/lib/{generators/active_record/templates/remove_merit_fields_from_model.rb → merit/generators/active_record/templates/remove_merit_fields_from_model.erb} +0 -0
- data/lib/{generators/active_record/templates/remove_merit_tables.rb → merit/generators/active_record/templates/remove_merit_tables.erb} +0 -0
- data/lib/merit/generators/install_generator.rb +21 -0
- data/lib/{generators/merit → merit/generators}/merit_generator.rb +7 -2
- data/lib/{generators/merit → merit/generators}/remove_generator.rb +7 -2
- data/lib/{generators/merit/templates/merit.rb → merit/generators/templates/merit.erb} +13 -14
- data/lib/{generators/merit/templates/merit_badge_rules.rb → merit/generators/templates/merit_badge_rules.erb} +0 -0
- data/lib/{generators/merit/templates/merit_point_rules.rb → merit/generators/templates/merit_point_rules.erb} +0 -0
- data/lib/{generators/merit/templates/merit_rank_rules.rb → merit/generators/templates/merit_rank_rules.erb} +0 -0
- data/lib/merit/judge.rb +6 -5
- data/{app/models/merit/action.rb → lib/merit/models/action_concern.rb} +12 -10
- data/lib/merit/models/active_record/{merit/action.rb → action.rb} +5 -1
- data/lib/merit/models/active_record/{merit/activity_log.rb → activity_log.rb} +3 -1
- data/lib/merit/models/active_record/{merit/badges_sash.rb → badges_sash.rb} +4 -2
- data/lib/merit/models/active_record/{merit/sash.rb → sash.rb} +5 -2
- data/lib/merit/models/active_record/{merit/score.rb → score.rb} +4 -1
- data/lib/merit/models/badges_sash_concern.rb +13 -0
- data/lib/merit/models/base/badges_sash.rb +1 -1
- data/lib/merit/models/base/sash.rb +1 -1
- data/lib/merit/models/sash_concern.rb +53 -0
- data/lib/merit/{rules_points_methods.rb → point_rules_methods.rb} +0 -0
- data/lib/merit/{rules_rank_methods.rb → rank_rules_methods.rb} +3 -18
- data/lib/merit.rb +29 -56
- data/merit.gemspec +5 -2
- data/test/dummy/app/models/address.rb +1 -12
- data/test/dummy/app/models/comment.rb +3 -21
- data/test/dummy/app/models/user.rb +1 -14
- data/test/dummy/config/application.rb +5 -1
- data/test/dummy/config/application_api_only.rb +1 -1
- data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -0
- data/test/dummy/db/schema.rb +4 -8
- data/test/integration/navigation_test.rb +3 -3
- data/test/test_helper.rb +0 -2
- data/test/unit/base_target_finder_test.rb +7 -26
- data/test/unit/merit_unit_test.rb +6 -8
- data/test/unit/rule_unit_test.rb +8 -8
- data/test/unit/rules_matcher_test.rb +9 -6
- data/test/unit/sash_finder_test.rb +5 -5
- data/test/unit/sash_test.rb +16 -0
- data/test/unit/score_test.rb +1 -1
- data/test/unit/target_finder_test.rb +13 -13
- metadata +64 -62
- data/UPGRADING.md +0 -256
- data/lib/generators/active_record/templates/add_target_data_to_merit_actions.rb +0 -5
- data/lib/generators/active_record/upgrade_generator.rb +0 -40
- data/lib/generators/merit/install_generator.rb +0 -16
- data/lib/generators/merit/upgrade_generator.rb +0 -7
- data/lib/merit/models/mongoid/merit/action.rb +0 -18
- data/lib/merit/models/mongoid/merit/activity_log.rb +0 -11
- data/lib/merit/models/mongoid/merit/badges_sash.rb +0 -20
- data/lib/merit/models/mongoid/merit/sash.rb +0 -30
- data/lib/merit/models/mongoid/merit/score.rb +0 -45
- data/test/dummy/db/migrate/20140906225844_create_players.rb +0 -8
- data/test/dummy/public/javascripts/application.js +0 -2
- data/test/dummy/public/javascripts/controls.js +0 -965
- data/test/dummy/public/javascripts/dragdrop.js +0 -974
- data/test/dummy/public/javascripts/effects.js +0 -1123
- data/test/dummy/public/javascripts/prototype.js +0 -6001
- data/test/dummy/public/javascripts/rails.js +0 -191
- data/test/orm_models/active_record.rb +0 -11
- data/test/orm_models/mongoid.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1163ea7681b5daca51eb89a7785bc648fe86ddbefff1a05cdc765c20c9b91973
|
4
|
+
data.tar.gz: 1329168f700f69f1d0eff4ca196ed511302b7839745eb8ed58bb5bb277cd5d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e112a21e6ada4964c86c7253c72bc4235f4ab478a876badfa27cf1d60d2cea3ec297f234219100bc9049e50ea859860a7d6c3f504dcca86b8424da3aa28e007
|
7
|
+
data.tar.gz: 39f8af732714702142e9b0f279c63b7aa528113fd81f39df99f94ae09ca0320e9a2f52b230dd919bedc9e42f5947aed9ad656df89c84c9bc09a56cdacd7e8438
|
data/Gemfile
CHANGED
@@ -4,16 +4,8 @@ gemspec
|
|
4
4
|
|
5
5
|
gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', 6.0)}"
|
6
6
|
|
7
|
-
case ENV['ORM']
|
8
|
-
when 'active_record'
|
9
|
-
gem 'activerecord'
|
10
|
-
when 'mongoid'
|
11
|
-
gem 'mongoid'
|
12
|
-
end
|
13
|
-
|
14
7
|
group :development, :test do
|
15
|
-
gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
|
16
8
|
gem 'sqlite3', '~> 1.4'
|
17
9
|
end
|
18
10
|
|
19
|
-
gem 'coveralls', require: false
|
11
|
+
gem 'coveralls', '~> 0.8.23', require: false
|
data/NEWS.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
User-visible changes worth mentioning.
|
4
4
|
|
5
|
+
## 4.0.3
|
6
|
+
|
7
|
+
- Add webrick as a development dependency
|
8
|
+
- [#363] Fix: `warning: already initialized constant Merit::*` messages
|
9
|
+
- [#357] Fix `merit_actions` migration template
|
10
|
+
|
11
|
+
## 4.0.2
|
12
|
+
|
13
|
+
- [#355, #356] Add index on merit_actions.processed column
|
14
|
+
- [#354] Fix Rails autoloader deprecation warnings
|
15
|
+
Requires wrapping `Merit::Badge.create` with `Rails.application.reloader.to_prepare`
|
16
|
+
- Test with Ruby 3 and Rails 6.1 (excludes Rails 5.2 with Ruby 3, that errors out)
|
17
|
+
- [#288] Don’t send “removed badge” notifications when user doesn’t have the badge
|
18
|
+
|
19
|
+
## 4.0.1
|
20
|
+
|
21
|
+
- [#351] Fix bug on generating migrations
|
22
|
+
|
23
|
+
## 4.0.0
|
24
|
+
|
25
|
+
- Stop testing on Rails 5.1
|
26
|
+
- Drop support for mongoid
|
27
|
+
- Drop v2 upgrade generators
|
28
|
+
- Enable Zeitwerk gem mode (and renames internal merit constants)
|
29
|
+
|
5
30
|
## 3.0.3
|
6
31
|
|
7
32
|
- Test against Ruby 2.6 and Rails 6
|
data/README.md
CHANGED
@@ -38,8 +38,7 @@ and Rankings.
|
|
38
38
|
2. Run `rails g merit:install`. This creates several migrations.
|
39
39
|
3. Run `rails g merit MODEL_NAME` (e.g. `user`). This creates a migration and adds `has_merit` to MODEL_NAME.
|
40
40
|
4. Run `rake db:migrate`
|
41
|
-
5. Define badges in `config/initializers/merit.rb
|
42
|
-
`:active_record` (default) or `:mongoid`.
|
41
|
+
5. Define badges in `config/initializers/merit.rb`
|
43
42
|
6. Configure reputation rules for your application in `app/models/merit/*`
|
44
43
|
|
45
44
|
|
@@ -59,12 +58,16 @@ Create badges in `config/initializers/merit.rb`
|
|
59
58
|
### Example
|
60
59
|
|
61
60
|
```ruby
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
61
|
+
# config/initializers/merit.rb
|
62
|
+
|
63
|
+
Rails.application.reloader.to_prepare do
|
64
|
+
Merit::Badge.create!(
|
65
|
+
id: 1,
|
66
|
+
name: "year-member",
|
67
|
+
description: "Active member for a year",
|
68
|
+
custom_fields: { difficulty: :silver }
|
69
|
+
)
|
70
|
+
end
|
68
71
|
```
|
69
72
|
|
70
73
|
## Defining Rules
|
@@ -114,6 +117,19 @@ grant_on ['users#create', 'users#update'], badge: 'autobiographer', temporary: t
|
|
114
117
|
end
|
115
118
|
```
|
116
119
|
|
120
|
+
If your controller is under a namespace other than root (example:
|
121
|
+
`Api::ModelController`) then for merit to find your object automatically you
|
122
|
+
must specify the model class and not forget that your action is of the form
|
123
|
+
`namespace/models#action`.
|
124
|
+
|
125
|
+
See an example of a `Post` model that belongs to user:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
grant_on 'api/posts#create', badge: 'first-post', model_name: 'Post', to: :user do |post|
|
129
|
+
post.user.posts.count >= 1
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
117
133
|
## Other Actions
|
118
134
|
|
119
135
|
```ruby
|
@@ -293,8 +309,8 @@ warning, with a comment to check the configuration for the rule.
|
|
293
309
|
|
294
310
|
# Getting Notifications
|
295
311
|
|
296
|
-
You can get observers notified any time merit changes reputation
|
297
|
-
application.
|
312
|
+
You can get observers notified any time merit automatically changes reputation
|
313
|
+
in your application.
|
298
314
|
|
299
315
|
It needs to implement the `update` method, which receives as parameter the
|
300
316
|
following hash:
|
@@ -325,6 +341,9 @@ end
|
|
325
341
|
config.add_observer 'ReputationChangeObserver'
|
326
342
|
```
|
327
343
|
|
344
|
+
**NOTE:** Observers won’t get notified if you grant reputation with
|
345
|
+
direct calls to `add_badge` or `add_point`.
|
346
|
+
|
328
347
|
# I18n
|
329
348
|
|
330
349
|
Merit uses default messages with I18n for notify alerts. To customize your app, you can set up your locale file:
|
data/app/models/merit/badge.rb
CHANGED
@@ -26,14 +26,6 @@ module Merit
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
def _mongoid_sash_in(sashes)
|
30
|
-
{:sash_id.in => sashes}
|
31
|
-
end
|
32
|
-
|
33
|
-
def _active_record_sash_in(sashes)
|
34
|
-
{sash_id: sashes}
|
35
|
-
end
|
36
|
-
|
37
29
|
class << self
|
38
30
|
def find_by_name_and_level(name, level)
|
39
31
|
badges = Merit::Badge.by_name(name)
|
@@ -51,7 +43,7 @@ module Merit
|
|
51
43
|
def _define_related_entries_method(meritable_class_name)
|
52
44
|
define_method(:"#{meritable_class_name.underscore.pluralize}") do
|
53
45
|
sashes = BadgesSash.where(badge_id: id).pluck(:sash_id)
|
54
|
-
meritable_class_name.constantize.where(
|
46
|
+
meritable_class_name.constantize.where(sash_id: sashes)
|
55
47
|
end
|
56
48
|
end
|
57
49
|
end
|
File without changes
|
@@ -9,7 +9,6 @@ module Merit
|
|
9
9
|
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1079-belongs_to-dependent-destroy-should-destroy-self-before-assocation
|
10
10
|
belongs_to :sash, class_name: 'Merit::Sash', inverse_of: nil, optional: true
|
11
11
|
|
12
|
-
send :"_merit_#{Merit.orm}_specific_config"
|
13
12
|
_merit_delegate_methods_to_sash
|
14
13
|
_merit_define_badge_related_entries_method
|
15
14
|
_merit_sash_initializer
|
@@ -22,16 +21,6 @@ module Merit
|
|
22
21
|
methods.each { |method| delegate method, to: :_sash }
|
23
22
|
end
|
24
23
|
|
25
|
-
def _merit_active_record_specific_config
|
26
|
-
end
|
27
|
-
|
28
|
-
def _merit_mongoid_specific_config
|
29
|
-
field :level, type: Integer, default: 0
|
30
|
-
def find_by_id(id)
|
31
|
-
where(_id: id).first
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
24
|
def _merit_define_badge_related_entries_method
|
36
25
|
meritable_class_name = name.demodulize
|
37
26
|
Merit::Badge._define_related_entries_method(meritable_class_name)
|
@@ -27,16 +27,8 @@ module Merit
|
|
27
27
|
had_errors: had_errors?,
|
28
28
|
target_model: controller_path,
|
29
29
|
target_id: target_id,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
def target_data_hash
|
34
|
-
if Merit::Action.new.respond_to?(:target_data)
|
35
|
-
{ target_data: target_object.to_yaml }
|
36
|
-
else
|
37
|
-
Merit.upgrade_target_data_warning
|
38
|
-
{}
|
39
|
-
end
|
30
|
+
target_data: target_object.to_yaml,
|
31
|
+
}
|
40
32
|
end
|
41
33
|
|
42
34
|
def rules_defined?
|
@@ -69,21 +61,11 @@ module Merit
|
|
69
61
|
|
70
62
|
def target_id
|
71
63
|
target_id = target_object.try(:id)
|
72
|
-
# If target_id is nil
|
73
|
-
|
74
|
-
if target_id.nil? && send("check_#{Merit.orm}_id", params[:id])
|
64
|
+
# If target_id is nil use (only digits of) params[:id]
|
65
|
+
if target_id.nil? && params[:id].to_s =~ /^[0-9]+$/
|
75
66
|
target_id = params[:id]
|
76
67
|
end
|
77
68
|
target_id
|
78
69
|
end
|
79
|
-
|
80
|
-
# This check avoids trying to set a slug as integer FK
|
81
|
-
def check_active_record_id(id)
|
82
|
-
id.to_s =~ /^[0-9]+$/
|
83
|
-
end
|
84
|
-
|
85
|
-
def check_mongoid_id(id)
|
86
|
-
id.to_s =~ /^[0-9a-fA-F]{24}$/
|
87
|
-
end
|
88
70
|
end
|
89
71
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
|
3
|
-
module
|
4
|
-
module Generators
|
5
|
-
class InstallGenerator < Rails::Generators::Base
|
3
|
+
module Merit
|
4
|
+
module Generators::ActiveRecord
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
6
|
include Rails::Generators::Migration
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -13,19 +13,19 @@ module ActiveRecord
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def copy_migrations_and_model
|
16
|
-
migration_template 'create_merit_actions.
|
16
|
+
migration_template 'create_merit_actions.erb',
|
17
17
|
'db/migrate/create_merit_actions.rb'
|
18
18
|
|
19
|
-
migration_template 'create_merit_activity_logs.
|
19
|
+
migration_template 'create_merit_activity_logs.erb',
|
20
20
|
'db/migrate/create_merit_activity_logs.rb'
|
21
21
|
|
22
|
-
migration_template 'create_sashes.
|
22
|
+
migration_template 'create_sashes.erb',
|
23
23
|
'db/migrate/create_sashes.rb'
|
24
24
|
|
25
|
-
migration_template 'create_badges_sashes.
|
25
|
+
migration_template 'create_badges_sashes.erb',
|
26
26
|
'db/migrate/create_badges_sashes.rb'
|
27
27
|
|
28
|
-
migration_template 'create_scores_and_points.
|
28
|
+
migration_template 'create_scores_and_points.erb',
|
29
29
|
'db/migrate/create_scores_and_points.rb'
|
30
30
|
end
|
31
31
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
|
3
|
-
module
|
4
|
-
module Generators
|
5
|
-
class MeritGenerator < ActiveRecord::Generators::Base
|
3
|
+
module Merit
|
4
|
+
module Generators::ActiveRecord
|
5
|
+
class MeritGenerator < ::ActiveRecord::Generators::Base
|
6
6
|
include Rails::Generators::Migration
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -13,7 +13,7 @@ module ActiveRecord
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def copy_migrations_and_model
|
16
|
-
migration_template 'add_merit_fields_to_model.
|
16
|
+
migration_template 'add_merit_fields_to_model.erb',
|
17
17
|
"db/migrate/add_merit_fields_to_#{table_name}.rb"
|
18
18
|
end
|
19
19
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rails/generators/active_record'
|
2
2
|
|
3
|
-
module
|
4
|
-
module Generators
|
5
|
-
class RemoveGenerator < ActiveRecord::Generators::Base
|
3
|
+
module Merit
|
4
|
+
module Generators::ActiveRecord
|
5
|
+
class RemoveGenerator < ::ActiveRecord::Generators::Base
|
6
6
|
include Rails::Generators::Migration
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -13,11 +13,11 @@ module ActiveRecord
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def copy_migrations_and_model
|
16
|
-
migration_template 'remove_merit_tables.
|
16
|
+
migration_template 'remove_merit_tables.erb',
|
17
17
|
'db/migrate/remove_merit_tables.rb'
|
18
18
|
|
19
19
|
migration_template(
|
20
|
-
'remove_merit_fields_from_model.
|
20
|
+
'remove_merit_fields_from_model.erb',
|
21
21
|
"db/migrate/remove_merit_fields_from_#{table_name}.rb"
|
22
22
|
)
|
23
23
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -7,7 +7,7 @@ class CreateScoresAndPoints < ActiveRecord::Migration<%= migration_version %>
|
|
7
7
|
|
8
8
|
create_table :merit_score_points do |t|
|
9
9
|
t.references :score
|
10
|
-
t.
|
10
|
+
t.bigint :num_points, default: 0
|
11
11
|
t.string :log
|
12
12
|
t.datetime :created_at
|
13
13
|
end
|
File without changes
|
File without changes
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Merit
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
7
|
+
|
8
|
+
desc 'Copy config and rules files'
|
9
|
+
def copy_migrations_and_model
|
10
|
+
template 'merit.erb', 'config/initializers/merit.rb'
|
11
|
+
template 'merit_badge_rules.erb', 'app/models/merit/badge_rules.rb'
|
12
|
+
template 'merit_point_rules.erb', 'app/models/merit/point_rules.rb'
|
13
|
+
template 'merit_rank_rules.erb', 'app/models/merit/rank_rules.rb'
|
14
|
+
end
|
15
|
+
|
16
|
+
def run_active_record_generators
|
17
|
+
invoke 'merit:active_record:install'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
1
3
|
module Merit
|
2
4
|
module Generators
|
3
|
-
class MeritGenerator < Rails::Generators::NamedBase
|
5
|
+
class MeritGenerator < ::Rails::Generators::NamedBase
|
4
6
|
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
hook_for :orm
|
6
7
|
|
7
8
|
def inject_merit_content
|
8
9
|
if model_exists?
|
@@ -10,6 +11,10 @@ module Merit
|
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
14
|
+
def run_active_record_generators
|
15
|
+
invoke 'merit:active_record:merit'
|
16
|
+
end
|
17
|
+
|
13
18
|
private
|
14
19
|
|
15
20
|
def model_exists?
|
@@ -1,8 +1,13 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
1
3
|
module Merit
|
2
4
|
module Generators
|
3
|
-
class RemoveGenerator < Rails::Generators::NamedBase
|
5
|
+
class RemoveGenerator < ::Rails::Generators::NamedBase
|
4
6
|
source_root File.expand_path('../templates', __FILE__)
|
5
|
-
|
7
|
+
|
8
|
+
def run_active_record_generators
|
9
|
+
invoke 'merit:active_record:remove'
|
10
|
+
end
|
6
11
|
|
7
12
|
private
|
8
13
|
|
@@ -3,13 +3,10 @@ Merit.setup do |config|
|
|
3
3
|
# Check rules on each request or in background
|
4
4
|
# config.checks_on_each_request = true
|
5
5
|
|
6
|
-
# Define ORM. Could be :active_record (default) and :mongoid
|
7
|
-
# config.orm = :active_record
|
8
|
-
|
9
6
|
# Add application observers to get notifications when reputation changes.
|
10
7
|
# config.add_observer 'MyObserverClassName'
|
11
8
|
|
12
|
-
# Define :user_model_name. This model will be used to
|
9
|
+
# Define :user_model_name. This model will be used to grant badge if no
|
13
10
|
# `:to` option is given. Default is 'User'.
|
14
11
|
# config.user_model_name = 'User'
|
15
12
|
|
@@ -20,14 +17,16 @@ Merit.setup do |config|
|
|
20
17
|
end
|
21
18
|
|
22
19
|
# Create application badges (uses https://github.com/norman/ambry)
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
20
|
+
# Rails.application.reloader.to_prepare do
|
21
|
+
# badge_id = 0
|
22
|
+
# [{
|
23
|
+
# id: (badge_id = badge_id+1),
|
24
|
+
# name: 'just-registered'
|
25
|
+
# }, {
|
26
|
+
# id: (badge_id = badge_id+1),
|
27
|
+
# name: 'best-unicorn',
|
28
|
+
# custom_fields: { category: 'fantasy' }
|
29
|
+
# }].each do |attrs|
|
30
|
+
# Merit::Badge.create! attrs
|
31
|
+
# end
|
33
32
|
# end
|
File without changes
|
File without changes
|
File without changes
|
data/lib/merit/judge.rb
CHANGED
@@ -50,11 +50,12 @@ module Merit
|
|
50
50
|
|
51
51
|
def remove_badges
|
52
52
|
sashes.each do |sash|
|
53
|
-
sash.rm_badge badge.id
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
if sash.rm_badge badge.id
|
54
|
+
notify_observers(
|
55
|
+
description: I18n.t("merit.removed_badge", badge_name: badge.name),
|
56
|
+
sash_id: sash.id
|
57
|
+
)
|
58
|
+
end
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require_dependency "merit/models/#{Merit.orm}/merit/action"
|
2
|
-
|
3
1
|
# Merit::Action general schema
|
4
2
|
# ______________________________________________________________
|
5
3
|
# source | action | target
|
@@ -12,10 +10,14 @@ require_dependency "merit/models/#{Merit.orm}/merit/action"
|
|
12
10
|
# ______________________________________________________________
|
13
11
|
#
|
14
12
|
# Rules relate to merit_actions by action name ('controller#action' string)
|
15
|
-
module Merit
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
module Merit::Models
|
14
|
+
module ActionConcern
|
15
|
+
extend ActiveSupport::Concern
|
16
|
+
|
17
|
+
class_methods do
|
18
|
+
def check_unprocessed
|
19
|
+
where(processed: false).find_each(&:check_all_rules)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
|
21
23
|
# Check rules defined for a merit_action
|
@@ -23,16 +25,16 @@ module Merit
|
|
23
25
|
mark_as_processed!
|
24
26
|
return if had_errors
|
25
27
|
|
26
|
-
check_rules rules_matcher.select_from(AppBadgeRules), :badges
|
27
|
-
check_rules rules_matcher.select_from(AppPointRules), :points
|
28
|
+
check_rules rules_matcher.select_from(Merit::AppBadgeRules), :badges
|
29
|
+
check_rules rules_matcher.select_from(Merit::AppPointRules), :points
|
28
30
|
end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
34
|
def check_rules(rules_array, badges_or_points)
|
33
35
|
rules_array.each do |rule|
|
34
|
-
judge = Judge.new
|
35
|
-
judge.
|
36
|
+
judge = Merit::Judge.new(rule, action: self)
|
37
|
+
judge.public_send(:"apply_#{badges_or_points}")
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -1,7 +1,11 @@
|
|
1
|
-
module Merit
|
1
|
+
module Merit::Models::ActiveRecord
|
2
2
|
class Action < ActiveRecord::Base
|
3
|
+
include Merit::Models::ActionConcern
|
4
|
+
|
3
5
|
self.table_name = :merit_actions
|
4
6
|
|
5
7
|
has_many :activity_logs, class_name: 'Merit::ActivityLog'
|
6
8
|
end
|
7
9
|
end
|
10
|
+
|
11
|
+
class Merit::Action < Merit::Models::ActiveRecord::Action; end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Merit
|
1
|
+
module Merit::Models::ActiveRecord
|
2
2
|
class ActivityLog < ActiveRecord::Base
|
3
3
|
self.table_name = :merit_activity_logs
|
4
4
|
|
@@ -7,3 +7,5 @@ module Merit
|
|
7
7
|
has_one :sash, through: :related_change
|
8
8
|
end
|
9
9
|
end
|
10
|
+
|
11
|
+
class Merit::ActivityLog < Merit::Models::ActiveRecord::ActivityLog; end
|
@@ -1,6 +1,6 @@
|
|
1
|
-
module Merit
|
1
|
+
module Merit::Models::ActiveRecord
|
2
2
|
class BadgesSash < ActiveRecord::Base
|
3
|
-
include
|
3
|
+
include Merit::Models::BadgesSashConcern
|
4
4
|
|
5
5
|
has_many :activity_logs,
|
6
6
|
class_name: 'Merit::ActivityLog',
|
@@ -9,3 +9,5 @@ module Merit
|
|
9
9
|
validates_presence_of :badge_id, :sash
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
class Merit::BadgesSash < Merit::Models::ActiveRecord::BadgesSash; end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Merit
|
1
|
+
module Merit::Models::ActiveRecord
|
2
2
|
# Sash is a container for reputation data for meritable models. It's an
|
3
3
|
# indirection between meritable models and badges and scores (one to one
|
4
4
|
# relationship).
|
@@ -6,7 +6,8 @@ module Merit
|
|
6
6
|
# It's existence make join models like badges_users and scores_users
|
7
7
|
# unnecessary. It should be transparent at the application.
|
8
8
|
class Sash < ActiveRecord::Base
|
9
|
-
include
|
9
|
+
include Merit::Models::SashConcern
|
10
|
+
|
10
11
|
has_many :badges_sashes, dependent: :destroy
|
11
12
|
has_many :scores, dependent: :destroy, class_name: 'Merit::Score'
|
12
13
|
|
@@ -27,3 +28,5 @@ module Merit
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
end
|
31
|
+
|
32
|
+
class Merit::Sash < Merit::Models::ActiveRecord::Sash; end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module Merit
|
1
|
+
module Merit::Models::ActiveRecord
|
2
2
|
class Score < ActiveRecord::Base
|
3
3
|
self.table_name = :merit_scores
|
4
4
|
belongs_to :sash
|
@@ -20,3 +20,6 @@ module Merit
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
class Merit::Score < Merit::Models::ActiveRecord::Score; end
|
25
|
+
class Merit::Score::Point < Merit::Models::ActiveRecord::Score::Point; end
|