wfl_simple_activity 0.1.9 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb07938e75e645aa72551e8626b37338fc2e9f5a1b0201c941246d53390aee43
4
- data.tar.gz: 907f485b24a088d0e76c3e8ada74cffc1e6ff5065f9508ea4c59350f3b8d5625
3
+ metadata.gz: 673204e78ec26a69f4061a1664732d6f7d328501eba76f9afad2b001daac95cd
4
+ data.tar.gz: 6b6bc9d45fde533189b74e3266060133fd38c932d4428b8295d7fbd00845e321
5
5
  SHA512:
6
- metadata.gz: 056fbcc244291f2c74335ea5f52b052bcca3af940a0d9912c265a65e81a0ac89b35c35d7889e337dbb321a0720af54813941c68cb0e6402e1f98d67b927bed9a
7
- data.tar.gz: 52f1cf876b6926c0aeb6d9c92cbbed65eaf7daa596b982e67216d75ed3ff562d165f9221f0c34b4a1f42e0bb6475b00d5d3f0967d467bc3135b004e661cd33dd
6
+ metadata.gz: 8063e654ee7ad4031d5bf6f36bc6a7a595f2afab471bfaa92bf3ef4facb03390c7c2200b8c6706470721671f93d93a7694a1e508f8e7775e46fb9ad42550b023
7
+ data.tar.gz: d069374db2aa1951128d4348a4fea53590287c155bb2d23ba05240c56d61f99c9702a6b07bff20bc16f644bf85bb0c68b2ea73549ddfe79b38603961e4b5d0ec
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # WflSimpleActivity
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wfl_simple_activity`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ 一个用以记录用户数据操作日志的Gem
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
5
+ ## 安装
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
@@ -20,16 +18,31 @@ Or install it yourself as:
20
18
 
21
19
  $ gem install wfl_simple_activity
22
20
 
23
- ## Usage
21
+ ## 用法
24
22
 
25
23
  $ rails g wfl_simple_activity:install
26
24
  $ rake db:migrate
27
25
 
28
- ## Development
26
+ ## 开发
27
+
28
+ #### 单表记录
29
+ * 执行上面两步之后,在需要记录数据变更的Model中 `include WflActivity` ,这样便会记录该Model的数据变更日志,在
30
+ 数据发生变化,将会创建 `activity`, 在项目中可以通过 `model_name.activities` 或者 `PublicActivity::Activity.where(condition)`来获取活动日志
31
+
32
+ #### 关联表记录 或者 其余特殊情况
33
+
34
+ * 如果需要在关联模型数据发生变更时记录当前模型的`activity`,需要自行在关联的模型中通过`model_name.create_activity key: 'article.commented_on', owner: current_user, recipient: recipientm`来创建`activity`,create_activity方法参数可参考 [PublicActivity::Common#create_activity](https://rubydoc.info/gems/public_activity/PublicActivity/Common:create_activity)
35
+
36
+ #### 注意事项
37
+
38
+ * 生成的migration文件中需自行migration版本指定对应的版本
29
39
 
30
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
+ * 如果需要记录current_user 或者 调用其他在controller中的方法,需要在 `application_controller.rb`中 `include PublicActivity::StoreController`
31
41
 
32
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
42
+ * 自行获取 controller 上下文:
43
+ ```ruby
44
+ PublicActivity.get_controller
45
+ ```
33
46
 
34
47
  ## Contributing
35
48
 
@@ -20,7 +20,7 @@ module WflSimpleActivity
20
20
  end
21
21
 
22
22
  def copy_common_activity
23
- copy_file "common_activity.rb", "app/models/common_activity.rb"
23
+ copy_file "wfl_activity.rb", "app/models/concerns/wfl_activity.rb"
24
24
  end
25
25
 
26
26
  def copy_activity_model
@@ -0,0 +1,27 @@
1
+ module WflActivity
2
+ extend ActiveSupport::Concern
3
+ included do |base|
4
+ include PublicActivity::Model
5
+ tracked(
6
+ owner: proc { |controller, model| controller&.current_user },
7
+ model_changes: proc {|controller, model| model.changes},
8
+ recipient: proc { |controller, model| model },
9
+ params: {
10
+ request_params: proc {|controller, model| controller&.params&.to_h}
11
+ }
12
+ )
13
+
14
+ # 如果不需要删除记录
15
+ # has_many :activities, as: :trackable, class_name: 'PublicActivity::Activity', dependent: :destroy
16
+
17
+ after_rollback proc {
18
+ # 由于after_rollback是ActiveRecord自带的回调,并不支持获取controller,所以需要借助PublicActivity
19
+ controller = PublicActivity.get_controller
20
+ if self.id.blank?
21
+ PublicActivity::Activity.create key: "#{self.class.name.underscore}.failed", owner: controller&.current_user, parameters: controller&.params&.to_h, model_changes: self.changes
22
+ else
23
+ self.create_activity key: "#{self.class.name.underscore}.failed", owner: User.find(Thread.current[:user_id]), recipient: self
24
+ end
25
+ }
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module WflSimpleActivity
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.15"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wfl_simple_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - longhaoran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2019-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: public_activity
@@ -67,8 +67,8 @@ files:
67
67
  - bin/setup
68
68
  - lib/generators/wfl_simple_activity/install_generator.rb
69
69
  - lib/generators/wfl_simple_activity/templates/activity.rb
70
- - lib/generators/wfl_simple_activity/templates/common_activity.rb
71
70
  - lib/generators/wfl_simple_activity/templates/create_activities.rb
71
+ - lib/generators/wfl_simple_activity/templates/wfl_activity.rb
72
72
  - lib/wfl_simple_activity.rb
73
73
  - lib/wfl_simple_activity/common_activity.rb
74
74
  - lib/wfl_simple_activity/version.rb
@@ -1,14 +0,0 @@
1
- module CommonActivity
2
- extend ActiveSupport::Concern
3
- included do |base|
4
- include PublicActivity::Model
5
- tracked(
6
- owner: proc { |controller, model| controller&.current_user },
7
- model_changes: proc {|controller, model| model.changes},
8
- recipient: proc { |controller, model| model },
9
- params: {
10
- request_params: proc {|controller, model| controller&.params&.to_h}
11
- }
12
- )
13
- end
14
- end