merit 2.4.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +3 -35
  3. data/NEWS.md +31 -0
  4. data/README.md +15 -3
  5. data/RELEASING.md +16 -0
  6. data/Rakefile +13 -1
  7. data/app/models/merit/badge.rb +2 -19
  8. data/lib/merit.rb +13 -35
  9. data/lib/merit/{rules_badge_methods.rb → badge_rules_methods.rb} +0 -0
  10. data/lib/merit/base_target_finder.rb +1 -6
  11. data/lib/merit/{model_additions.rb → class_methods.rb} +2 -19
  12. data/lib/merit/controller_extensions.rb +13 -30
  13. data/lib/{generators → merit/generators}/active_record/install_generator.rb +12 -8
  14. data/lib/{generators → merit/generators}/active_record/merit_generator.rb +7 -3
  15. data/lib/{generators → merit/generators}/active_record/remove_generator.rb +9 -5
  16. data/lib/{generators/active_record/templates/add_merit_fields_to_model.rb → merit/generators/active_record/templates/add_merit_fields_to_model.erb} +1 -1
  17. data/lib/{generators/active_record/templates/create_badges_sashes.rb → merit/generators/active_record/templates/create_badges_sashes.erb} +1 -1
  18. data/lib/{generators/active_record/templates/create_merit_actions.rb → merit/generators/active_record/templates/create_merit_actions.erb} +2 -2
  19. data/lib/{generators/active_record/templates/create_merit_activity_logs.rb → merit/generators/active_record/templates/create_merit_activity_logs.erb} +1 -1
  20. data/lib/merit/generators/active_record/templates/create_sashes.erb +7 -0
  21. data/lib/{generators/active_record/templates/create_scores_and_points.rb → merit/generators/active_record/templates/create_scores_and_points.erb} +2 -2
  22. data/lib/{generators/active_record/templates/remove_merit_fields_from_model.rb → merit/generators/active_record/templates/remove_merit_fields_from_model.erb} +1 -1
  23. data/lib/{generators/active_record/templates/remove_merit_tables.rb → merit/generators/active_record/templates/remove_merit_tables.erb} +1 -1
  24. data/lib/merit/generators/install_generator.rb +18 -0
  25. data/lib/{generators/merit → merit/generators}/merit_generator.rb +3 -1
  26. data/lib/{generators/merit → merit/generators}/remove_generator.rb +3 -1
  27. data/lib/{generators/merit/templates/merit.rb → merit/generators/templates/merit.erb} +0 -3
  28. data/lib/{generators/merit/templates/merit_badge_rules.rb → merit/generators/templates/merit_badge_rules.erb} +0 -0
  29. data/lib/{generators/merit/templates/merit_point_rules.rb → merit/generators/templates/merit_point_rules.erb} +0 -0
  30. data/lib/{generators/merit/templates/merit_rank_rules.rb → merit/generators/templates/merit_rank_rules.erb} +0 -0
  31. data/{app/models/merit/action.rb → lib/merit/models/action_concern.rb} +12 -10
  32. data/lib/merit/models/active_record/action.rb +11 -0
  33. data/lib/merit/models/active_record/{merit/activity_log.rb → activity_log.rb} +4 -6
  34. data/lib/merit/models/active_record/{merit/badges_sash.rb → badges_sash.rb} +4 -4
  35. data/lib/merit/models/active_record/{merit/sash.rb → sash.rb} +5 -2
  36. data/lib/merit/models/active_record/{merit/score.rb → score.rb} +4 -1
  37. data/lib/merit/models/badges_sash_concern.rb +13 -0
  38. data/lib/merit/models/base/badges_sash.rb +1 -1
  39. data/lib/merit/models/base/sash.rb +1 -1
  40. data/lib/merit/models/sash_concern.rb +53 -0
  41. data/lib/merit/{rules_points_methods.rb → point_rules_methods.rb} +0 -0
  42. data/lib/merit/{rules_rank_methods.rb → rank_rules_methods.rb} +3 -18
  43. data/merit.gemspec +7 -5
  44. data/test/dummy/app/controllers/comments_controller.rb +1 -1
  45. data/test/dummy/app/controllers/registrations_controller.rb +1 -1
  46. data/test/dummy/app/models/address.rb +1 -12
  47. data/test/dummy/app/models/comment.rb +3 -25
  48. data/test/dummy/app/models/user.rb +1 -18
  49. data/test/dummy/config/application.rb +8 -10
  50. data/test/dummy/config/application_api_only.rb +28 -0
  51. data/test/dummy/config/environment_api_only.rb +7 -0
  52. data/test/dummy/config/environments/test.rb +1 -1
  53. data/test/dummy/config/initializers/new_framework_defaults.rb +3 -0
  54. data/test/dummy/db/migrate/20110421191249_create_users.rb +2 -2
  55. data/test/dummy/db/migrate/20110421191250_create_comments.rb +2 -2
  56. data/test/dummy/db/migrate/20120318022220_add_fields_to_users.rb +1 -1
  57. data/test/dummy/db/migrate/20130321082817_add_fields_to_comments.rb +1 -1
  58. data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -2
  59. data/test/dummy/db/migrate/20130329224407_create_merit_activity_logs.rb +1 -1
  60. data/test/dummy/db/migrate/20130329224408_create_sashes.rb +2 -2
  61. data/test/dummy/db/migrate/20130329224409_create_badges_sashes.rb +1 -1
  62. data/test/dummy/db/migrate/20130329224410_create_scores_and_points.rb +1 -1
  63. data/test/dummy/db/migrate/20140211144001_create_addresses.rb +1 -1
  64. data/test/dummy/db/migrate/20140819133931_add_target_data_to_merit_actions.rb +1 -1
  65. data/test/dummy/db/schema.rb +55 -59
  66. data/test/integration/navigation_test.rb +2 -2
  67. data/test/test_helper.rb +11 -12
  68. data/test/unit/base_target_finder_test.rb +7 -26
  69. data/test/unit/merit_unit_test.rb +13 -17
  70. data/test/unit/rule_unit_test.rb +15 -8
  71. data/test/unit/rules_matcher_test.rb +9 -6
  72. data/test/unit/sash_finder_test.rb +5 -5
  73. data/test/unit/score_test.rb +1 -1
  74. data/test/unit/target_finder_test.rb +13 -13
  75. metadata +61 -70
  76. data/UPGRADING.md +0 -256
  77. data/lib/generators/active_record/templates/add_target_data_to_merit_actions.rb +0 -5
  78. data/lib/generators/active_record/templates/create_sashes.rb +0 -7
  79. data/lib/generators/active_record/upgrade_generator.rb +0 -36
  80. data/lib/generators/merit/install_generator.rb +0 -16
  81. data/lib/generators/merit/upgrade_generator.rb +0 -7
  82. data/lib/merit/models/active_record/merit/action.rb +0 -12
  83. data/lib/merit/models/mongoid/merit/action.rb +0 -18
  84. data/lib/merit/models/mongoid/merit/activity_log.rb +0 -11
  85. data/lib/merit/models/mongoid/merit/badges_sash.rb +0 -22
  86. data/lib/merit/models/mongoid/merit/sash.rb +0 -30
  87. data/lib/merit/models/mongoid/merit/score.rb +0 -45
  88. data/test/dummy/db/migrate/20140906225844_create_players.rb +0 -8
  89. data/test/dummy/public/javascripts/application.js +0 -2
  90. data/test/dummy/public/javascripts/controls.js +0 -965
  91. data/test/dummy/public/javascripts/dragdrop.js +0 -974
  92. data/test/dummy/public/javascripts/effects.js +0 -1123
  93. data/test/dummy/public/javascripts/prototype.js +0 -6001
  94. data/test/dummy/public/javascripts/rails.js +0 -191
  95. data/test/orm/active_record.rb +0 -2
  96. data/test/orm/mongoid.rb +0 -6
  97. data/test/orm_models/active_record.rb +0 -11
  98. data/test/orm_models/mongoid.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c1d70d0ff56841cebd7bfb79bf17a152ba0a8156
4
- data.tar.gz: c602f5a16bbe014cd78ba2fc5d5eeec1ee9ac362
2
+ SHA256:
3
+ metadata.gz: f0ee557f98d45fe9a83d5de23d407e2b36f85f6a5d4204b1ed89fec8bf5c90fb
4
+ data.tar.gz: ae393531c2a569a8aece0d533523aaa6fa6e407c4fe4aa3efe96f49d349b3d37
5
5
  SHA512:
6
- metadata.gz: 5a8a44e81bddc1a740ebfb860eabefa2314f136c19851f5011113b1e25e4f539bb86affa4c9d447c6768f77b5c0a6b107258563a7bc41bd0b16ec86b24bd7a72
7
- data.tar.gz: 4e8523ab4e5c04583184da68b1aa5ff9937f053ad39c3756d10526bf9fde5f1e93c54d2d209c65b3f8c811e8d1bc21c15a475faa688eef5021ab363ee97bfe3c
6
+ metadata.gz: c4b48c33d57774076e00d9732ccac73dbb71b1ee1efe87329ba9ee542593e1a8c3823bef1c5c783a45ed46b28cc3eda4626ddefe9683682341ccc8d51bcf9889
7
+ data.tar.gz: 0e886c1d895343875d06c537015d4ae14b0723f96d8ddac2a264892b7a3aee0d821f7e6ccb404f68371ac9ca9d5adad78f211b1943747a9bc6dc53361efd6cb6
data/Gemfile CHANGED
@@ -2,42 +2,10 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- version = ENV['RAILS_VERSION'] || '4.2'
6
- rails = case version
7
- when 'master'
8
- { github: 'rails/rails' }
9
- when '4.0-protected-attributes'
10
- gem 'protected_attributes'
11
- "~> 4.0.0"
12
- when /4\.0|4\.1/
13
- "~> #{version}.0"
14
- when /4\.2/
15
- "~> #{version}.0.rc3"
16
- when '3.2'
17
- gem 'strong_parameters'
18
- "~> #{version}.0"
19
- end
20
-
21
- gem 'rails', rails
22
-
23
- case ENV['ORM']
24
- when 'active_record'
25
- gem 'activerecord'
26
- when 'mongoid'
27
- gem 'mongoid'
28
- end
5
+ gem 'rails', "~> #{ENV.fetch('RAILS_VERSION', 6.0)}"
29
6
 
30
7
  group :development, :test do
31
- gem 'activerecord-jdbcsqlite3-adapter', :platforms => [:jruby]
32
- gem 'sqlite3', '~> 1.3.8', :platforms => [:ruby, :mswin, :mingw]
33
- end
34
-
35
- platforms :rbx do
36
- gem 'rubysl', '~> 2.0'
37
- gem 'psych'
38
- gem 'racc'
39
- gem 'minitest'
40
- gem 'rubinius-developer_tools'
8
+ gem 'sqlite3', '~> 1.4'
41
9
  end
42
10
 
43
- gem 'coveralls', require: false
11
+ gem 'coveralls', '~> 0.8.23', require: false
data/NEWS.md CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  User-visible changes worth mentioning.
4
4
 
5
+ ## 4.0.0
6
+
7
+ - Stop testing on Rails 5.1
8
+ - Drop support for mongoid
9
+ - Drop v2 upgrade generators
10
+ - Enable Zeitwerk gem mode (and renames internal merit constants)
11
+
12
+ ## 3.0.3
13
+
14
+ - Test against Ruby 2.6 and Rails 6
15
+ - Use `find_each` in favor of `map` in `Merit::Action.check_unprocessed`
16
+ - Allow finding badges defined with symbol names
17
+ - Remove `Badge#last_granted` method (deprecated in merit <2.0)
18
+
19
+ ## 3.0.2
20
+
21
+ - [#287] Make Sash an optional dependency, fixing issues in Rails 5.1.
22
+ - [#297] Initialize merit once both for API or non-API apps
23
+ - Updates dependencies
24
+
25
+ ## 3.0.1
26
+
27
+ - [#282] Run action controller load hook only once
28
+ - [#284] Add migration version to active record migrations
29
+ - Add RELEASING.md document
30
+
31
+ ## 3.0.0
32
+
33
+ - [#276] Drops Rails <5 version support. Drops deprecated `action_filter` call.
34
+ - Fix deprecation warnings
35
+
5
36
  ## 2.4.0
6
37
 
7
38
  - [#260] Works with Rails 5
data/README.md CHANGED
@@ -4,7 +4,7 @@ Merit adds reputation behavior to Rails apps in the form of Badges, Points,
4
4
  and Rankings.
5
5
 
6
6
  [![Build Status](https://travis-ci.org/merit-gem/merit.svg?branch=master)](http://travis-ci.org/merit-gem/merit)
7
- [![Coverage Status](https://img.shields.io/coveralls/tute/merit.svg)](https://coveralls.io/r/tute/merit?branch=master)
7
+ [![Coverage Status](https://coveralls.io/repos/github/merit-gem/merit/badge.svg?branch=master)](https://coveralls.io/github/merit-gem/merit?branch=master)
8
8
  [![Code Climate](https://codeclimate.com/github/tute/merit/badges/gpa.svg)](https://codeclimate.com/github/tute/merit)
9
9
 
10
10
  # Table of Contents
@@ -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`. You can also define ORM:
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
 
@@ -114,6 +113,19 @@ grant_on ['users#create', 'users#update'], badge: 'autobiographer', temporary: t
114
113
  end
115
114
  ```
116
115
 
116
+ If your controller is under a namespace other than root (example:
117
+ `Api::ModelController`) then for merit to find your object automatically you
118
+ must specify the model class and not forget that your action is of the form
119
+ `namespace/models#action`.
120
+
121
+ See an example of a `Post` model that belongs to user:
122
+
123
+ ```ruby
124
+ grant_on 'api/posts#create', badge: 'first-post', model_name: 'Post', to: :user do |post|
125
+ post.user.posts.count >= 1
126
+ end
127
+ ```
128
+
117
129
  ## Other Actions
118
130
 
119
131
  ```ruby
@@ -0,0 +1,16 @@
1
+ # Releasing
2
+
3
+ 1. Update `NEWS.md` to reflect the changes since last release.
4
+ 1. Tag the release: `git tag vVERSION -a -s`. The tag message should contain the
5
+ appropriate `NEWS.md` subsection.
6
+ 1. Push changes: `git push --tags`
7
+ 1. Build and publish to rubygems:
8
+ ```bash
9
+ gem build merit.gemspec
10
+ gem push merit-*.gem
11
+ ```
12
+
13
+ 1. Add a new GitHub release:
14
+ https://github.com/merit-gem/merit/releases/new?tag=vVERSION
15
+ 1. Announce the new release, making sure to say "thank you" to the contributors
16
+ who helped shape this version!
data/Rakefile CHANGED
@@ -8,7 +8,11 @@ end
8
8
  require 'rake/testtask'
9
9
 
10
10
  desc 'Default: run tests for all ORMs.'
11
- task default: :test
11
+ task default: [:setup, :test, :api_test]
12
+
13
+ task :setup do
14
+ system "cd test/dummy && rake db:migrate && rake db:test:prepare"
15
+ end
12
16
 
13
17
  Rake::TestTask.new(:test) do |t|
14
18
  t.libs << 'lib'
@@ -17,6 +21,14 @@ Rake::TestTask.new(:test) do |t|
17
21
  t.verbose = true
18
22
  end
19
23
 
24
+ Rake::TestTask.new(:api_test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.test_files = FileList['test/**/*_test.rb'].exclude(/navigation_test.rb/)
28
+ t.verbose = true
29
+ t.options = '-- -api-only'
30
+ end
31
+
20
32
  begin
21
33
  require 'rdoc/task'
22
34
  Rake::RDocTask.new(:rdoc) do |rdoc|
@@ -18,7 +18,7 @@ module Merit
18
18
  end
19
19
 
20
20
  def by_name(name)
21
- find { |b| b.name == name.to_s }
21
+ find { |b| b.name.to_s == name.to_s }
22
22
  end
23
23
 
24
24
  def by_level(level)
@@ -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)
@@ -45,22 +37,13 @@ module Merit
45
37
  badge
46
38
  end
47
39
 
48
- # DEPRECATED: `last_granted` will be removed from merit, please refer to:
49
- # https://github.com/tute/merit/wiki/How-to-show-last-granted-badges
50
- def last_granted(options = {})
51
- warn '[merit] [DEPRECATION] `last_granted` will be removed from merit, please refer to: https://github.com/tute/merit/wiki/How-to-show-last-granted-badges'
52
- options[:since_date] ||= 1.month.ago
53
- options[:limit] ||= 10
54
- BadgesSash.last_granted(options)
55
- end
56
-
57
40
  # Defines Badge#meritable_models method, to get related
58
41
  # entries with certain badge. For instance, Badge.find(3).users
59
42
  # orm-specified
60
43
  def _define_related_entries_method(meritable_class_name)
61
44
  define_method(:"#{meritable_class_name.underscore.pluralize}") do
62
45
  sashes = BadgesSash.where(badge_id: id).pluck(:sash_id)
63
- meritable_class_name.constantize.where(send "_#{Merit.orm}_sash_in", sashes)
46
+ meritable_class_name.constantize.where(sash_id: sashes)
64
47
  end
65
48
  end
66
49
  end
@@ -1,17 +1,4 @@
1
- require 'merit/rule'
2
- require 'merit/rules_badge_methods'
3
- require 'merit/rules_points_methods'
4
- require 'merit/rules_rank_methods'
5
- require 'merit/rules_matcher'
6
- require 'merit/controller_extensions'
7
- require 'merit/model_additions'
8
- require 'merit/judge'
9
- require 'merit/reputation_change_observer'
10
- require 'merit/sash_finder'
11
- require 'merit/base_target_finder'
12
- require 'merit/target_finder'
13
- require 'merit/models/base/sash'
14
- require 'merit/models/base/badges_sash'
1
+ require 'zeitwerk'
15
2
 
16
3
  module Merit
17
4
  def self.setup
@@ -24,7 +11,6 @@ module Merit
24
11
  @config.checks_on_each_request
25
12
  end
26
13
 
27
- # # Define ORM
28
14
  def self.orm
29
15
  @config.orm || :active_record
30
16
  end
@@ -49,11 +35,6 @@ module Merit
49
35
  @config.add_observer(class_name)
50
36
  end
51
37
 
52
- def self.upgrade_target_data_warning
53
- Rails.logger.warn '[merit] Missing column: target_data. Run `rails ' \
54
- 'generate merit:upgrade` and `rake db:migrate` to add it.'
55
- end
56
-
57
38
  class Configuration
58
39
  attr_accessor :checks_on_each_request, :orm, :user_model_name, :observers,
59
40
  :current_user_method
@@ -81,8 +62,7 @@ module Merit
81
62
 
82
63
  initializer 'merit.controller' do |app|
83
64
  extend_orm_with_has_merit
84
- require_models
85
- ActiveSupport.on_load(:action_controller) do
65
+ ActiveSupport.on_load(action_controller_hook) do
86
66
  begin
87
67
  # Load app rules on boot up
88
68
  Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
@@ -96,22 +76,20 @@ module Merit
96
76
  end
97
77
  end
98
78
 
99
- def require_models
100
- require 'merit/models/base/sash'
101
- require 'merit/models/base/badges_sash'
102
- require "merit/models/#{Merit.orm}/merit/activity_log"
103
- require "merit/models/#{Merit.orm}/merit/badges_sash"
104
- require "merit/models/#{Merit.orm}/merit/sash"
105
- require "merit/models/#{Merit.orm}/merit/score"
79
+ def extend_orm_with_has_merit
80
+ ActiveRecord::Base.include(Merit)
106
81
  end
107
82
 
108
- def extend_orm_with_has_merit
109
- if Object.const_defined?('ActiveRecord')
110
- ActiveRecord::Base.send :include, Merit
111
- end
112
- if Object.const_defined?('Mongoid')
113
- Mongoid::Document.send :include, Merit
83
+ def action_controller_hook
84
+ if Rails.application.config.api_only
85
+ :action_controller_api
86
+ else
87
+ :action_controller_base
114
88
  end
115
89
  end
116
90
  end
117
91
  end
92
+
93
+ loader = Zeitwerk::Loader.for_gem
94
+ loader.setup
95
+ loader.eager_load
@@ -25,12 +25,7 @@ module Merit
25
25
  end
26
26
 
27
27
  def reanimate_target_from_action
28
- if @action.respond_to? :target_data
29
- YAML.load(@action.target_data)
30
- else
31
- Merit.upgrade_target_data_warning
32
- nil
33
- end
28
+ YAML.load(@action.target_data)
34
29
  end
35
30
  end
36
31
  end
@@ -7,10 +7,8 @@ module Merit
7
7
  # That's why MeritableModel belongs_to Sash. Can't use
8
8
  # dependent: destroy as it may raise FK constraint exceptions. See:
9
9
  # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1079-belongs_to-dependent-destroy-should-destroy-self-before-assocation
10
- belongs_to :sash, class_name: 'Merit::Sash', inverse_of: nil
11
- attr_accessible :sash if show_attr_accessible?
10
+ belongs_to :sash, class_name: 'Merit::Sash', inverse_of: nil, optional: true
12
11
 
13
- send :"_merit_#{Merit.orm}_specific_config"
14
12
  _merit_delegate_methods_to_sash
15
13
  _merit_define_badge_related_entries_method
16
14
  _merit_sash_initializer
@@ -23,26 +21,11 @@ module Merit
23
21
  methods.each { |method| delegate method, to: :_sash }
24
22
  end
25
23
 
26
- def _merit_active_record_specific_config
27
- end
28
-
29
- def _merit_mongoid_specific_config
30
- field :level, type: Integer, default: 0
31
- def find_by_id(id)
32
- where(_id: id).first
33
- end
34
- end
35
-
36
24
  def _merit_define_badge_related_entries_method
37
25
  meritable_class_name = name.demodulize
38
26
  Merit::Badge._define_related_entries_method(meritable_class_name)
39
27
  end
40
28
 
41
- def show_attr_accessible?
42
- defined?(ProtectedAttributes) ||
43
- !defined?(ActionController::StrongParameters)
44
- end
45
-
46
29
  # _sash initializes a sash if doesn't have one yet.
47
30
  # From Rails 3.2 we can override association methods to do so
48
31
  # transparently, but merit supports Rails ~> 3.0.0. See:
@@ -50,7 +33,7 @@ module Merit
50
33
  def _merit_sash_initializer
51
34
  define_method(:_sash) do
52
35
  # TODO: reload.sash is not regression tested
53
- sash || reload.sash || update_attributes(sash: Sash.create)
36
+ sash || reload.sash || update(sash: Sash.create)
54
37
  sash
55
38
  end
56
39
  end
@@ -4,18 +4,19 @@ module Merit
4
4
  # 'controller_path#action_name'
5
5
  module ControllerExtensions
6
6
  def self.included(base)
7
- base.after_filter do |controller|
8
- if rules_defined?
9
- log_merit_action
10
- Merit::Action.check_unprocessed if Merit.checks_on_each_request
11
- end
12
- end
7
+ base.after_action :log_and_process
13
8
  end
14
9
 
15
10
  private
16
11
 
17
- def log_merit_action
18
- Merit::Action.create(merit_action_hash)
12
+ def log_and_process
13
+ if rules_defined?
14
+ Merit::Action.create(merit_action_hash)
15
+
16
+ if Merit.checks_on_each_request
17
+ Merit::Action.check_unprocessed
18
+ end
19
+ end
19
20
  end
20
21
 
21
22
  def merit_action_hash
@@ -26,16 +27,8 @@ module Merit
26
27
  had_errors: had_errors?,
27
28
  target_model: controller_path,
28
29
  target_id: target_id,
29
- }.merge(target_data_hash)
30
- end
31
-
32
- def target_data_hash
33
- if Merit::Action.new.respond_to?(:target_data)
34
- { target_data: target_object.to_yaml }
35
- else
36
- Merit.upgrade_target_data_warning
37
- {}
38
- end
30
+ target_data: target_object.to_yaml,
31
+ }
39
32
  end
40
33
 
41
34
  def rules_defined?
@@ -68,21 +61,11 @@ module Merit
68
61
 
69
62
  def target_id
70
63
  target_id = target_object.try(:id)
71
- # If target_id is nil
72
- # then use params[:id].
73
- 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]+$/
74
66
  target_id = params[:id]
75
67
  end
76
68
  target_id
77
69
  end
78
-
79
- # This check avoids trying to set a slug as integer FK
80
- def check_active_record_id(id)
81
- id.to_s =~ /^[0-9]+$/
82
- end
83
-
84
- def check_mongoid_id(id)
85
- id.to_s =~ /^[0-9a-fA-F]{24}$/
86
- end
87
70
  end
88
71
  end
@@ -1,8 +1,8 @@
1
1
  require 'rails/generators/active_record'
2
2
 
3
- module ActiveRecord
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,21 +13,25 @@ module ActiveRecord
13
13
  end
14
14
 
15
15
  def copy_migrations_and_model
16
- migration_template 'create_merit_actions.rb',
16
+ migration_template 'create_merit_actions.erb',
17
17
  'db/migrate/create_merit_actions.rb'
18
18
 
19
- migration_template 'create_merit_activity_logs.rb',
19
+ migration_template 'create_merit_activity_logs.erb',
20
20
  'db/migrate/create_merit_activity_logs.rb'
21
21
 
22
- migration_template 'create_sashes.rb',
22
+ migration_template 'create_sashes.erb',
23
23
  'db/migrate/create_sashes.rb'
24
24
 
25
- migration_template 'create_badges_sashes.rb',
25
+ migration_template 'create_badges_sashes.erb',
26
26
  'db/migrate/create_badges_sashes.rb'
27
27
 
28
- migration_template 'create_scores_and_points.rb',
28
+ migration_template 'create_scores_and_points.erb',
29
29
  'db/migrate/create_scores_and_points.rb'
30
30
  end
31
+
32
+ def migration_version
33
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
34
+ end
31
35
  end
32
36
  end
33
37
  end