user_activity 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +34 -0
- data/lib/generators/installer/USAGE +8 -0
- data/lib/generators/installer/installer_generator.rb +11 -0
- data/lib/generators/installer/templates/user_activity.rb +9 -0
- data/lib/generators/installer/templates/user_activity.yml +8 -0
- data/lib/user_activity.rb +24 -7
- data/lib/user_activity/version.rb +1 -1
- metadata +11 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca0ef675a19edb56bccd4933aeb5a52f5afc778c
|
4
|
+
data.tar.gz: c14aca3b123c5b806626ac68d988f8f73ec49bb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0172e301b263e2f9f9cd6b467aea8f5d28bc3ba9a7420baf97691e4dbe787431de5636ceffc5fc706a29e80e9f472f7b88809f58c1c0986de0446cbecd12ad64
|
7
|
+
data.tar.gz: 39a697f26056da1c91716ce41ecac37c7d10145e0672f1e0861e382240c8f537996b47a37f5217325b636d1357d881ecb3bc716cedecb379e48692189fbcbd6a
|
data/README.md
CHANGED
@@ -25,6 +25,10 @@ $ gem install user_activity
|
|
25
25
|
```bash
|
26
26
|
$ rails user_activity:install:migrations
|
27
27
|
```
|
28
|
+
And then execute:
|
29
|
+
```bash
|
30
|
+
$ rake db:migrate
|
31
|
+
```
|
28
32
|
|
29
33
|
### Mount route to application:
|
30
34
|
```ruby
|
@@ -34,6 +38,36 @@ Rails.application.routes.draw do
|
|
34
38
|
...
|
35
39
|
end
|
36
40
|
```
|
41
|
+
### Install initializer files by command below:
|
42
|
+
### Generate database table:
|
43
|
+
```bash
|
44
|
+
$ rails generate installer user_activity
|
45
|
+
```
|
46
|
+
|
47
|
+
##Configuration
|
48
|
+
It is posible to config some data in this gem, to do that you can follow the example below:
|
49
|
+
|
50
|
+
### Add before_action to enable recording activities
|
51
|
+
In case you want to enable to all controller in your application, you can add code to ApplicationController.
|
52
|
+
```ruby
|
53
|
+
class ApplicationController < ActionController::Base
|
54
|
+
...
|
55
|
+
before_action :log_user_activity
|
56
|
+
...
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
### To provide user name and user id you need to override controller method "user_for_user_activity"
|
61
|
+
Example in case using Devise
|
62
|
+
```ruby
|
63
|
+
class ApplicationController < ActionController::Base
|
64
|
+
...
|
65
|
+
def user_for_user_activity
|
66
|
+
Struct.new(:name, :id).new(current_user.email, current_user.id)
|
67
|
+
end
|
68
|
+
...
|
69
|
+
end
|
70
|
+
```
|
37
71
|
|
38
72
|
## Contributing
|
39
73
|
Contribution directions go here.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class InstallerGenerator < Rails::Generators::NamedBase
|
2
|
+
source_root File.expand_path('../templates', __FILE__)
|
3
|
+
|
4
|
+
def copy_initializer_file
|
5
|
+
copy_file "user_activity.rb", "config/initializers/user_activity.rb"
|
6
|
+
end
|
7
|
+
|
8
|
+
def copy_activity_definition_file
|
9
|
+
copy_file "user_activity.yml", "config/user_activity.yml"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# This file contains configurฟะรนื settings for UserActivity
|
4
|
+
|
5
|
+
UserActivity.configure do |config|
|
6
|
+
# Load activity define from yml file to configuration
|
7
|
+
# you can change activity define file path ans name here, by default we use the file that generated from gem
|
8
|
+
config.activity_define = YAML.load_file("#{Rails.root.to_s}/config/user_activity.yml") || {}
|
9
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
#This file was generated by user_activity gem to store activity define by using controller name and action name.
|
2
|
+
# below is an format and example
|
3
|
+
# comments:
|
4
|
+
# index: "comment view index activity"
|
5
|
+
# show: "visit comment activity"
|
6
|
+
# edit: "visit edit page comment activity"
|
7
|
+
# update: "update comment activity"
|
8
|
+
# destroy: "delete comment activity"
|
data/lib/user_activity.rb
CHANGED
@@ -2,19 +2,37 @@ require "active_support"
|
|
2
2
|
require "user_activity/engine"
|
3
3
|
|
4
4
|
module UserActivity
|
5
|
+
class << self
|
6
|
+
attr_accessor :configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
self.configuration ||= Configuration.new
|
11
|
+
yield(configuration)
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor :activity_define
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
@activity_define = {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
5
22
|
def tee_method
|
6
23
|
"Kraiyanat"
|
7
24
|
end
|
8
25
|
|
9
26
|
def user_for_user_activity
|
10
|
-
|
27
|
+
Struct.new(:name, :id).new("anonymus", "")
|
11
28
|
end
|
12
29
|
|
13
30
|
def activity_for_user_activity(controller, method)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
begin
|
32
|
+
configure.activity_define[controller][method]
|
33
|
+
rescue
|
34
|
+
""
|
35
|
+
end
|
18
36
|
end
|
19
37
|
|
20
38
|
def log_user_activity
|
@@ -23,7 +41,7 @@ module UserActivity
|
|
23
41
|
user_name: user_for_user_activity.name,
|
24
42
|
action: params[:action],
|
25
43
|
controller: params[:controller],
|
26
|
-
activity: activity_for_user_activity(
|
44
|
+
activity: activity_for_user_activity(params[:controller], params[:action]),
|
27
45
|
http_request: "#{request.method} #{request.url} #{request.params}"
|
28
46
|
)
|
29
47
|
end
|
@@ -38,5 +56,4 @@ end
|
|
38
56
|
|
39
57
|
ActiveSupport.on_load(:action_controller) do
|
40
58
|
include UserActivity
|
41
|
-
before_action :log_user_activity
|
42
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: user_activity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kraiyanat Chomchumpol
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 5.1
|
19
|
+
version: '5.1'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 5.1
|
26
|
+
version: '5.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails_admin
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: sqlite3
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: 'Easy to use gem, tracking all activity that user done and come with
|
@@ -76,11 +76,15 @@ files:
|
|
76
76
|
- config/initializers/rails_admin.rb
|
77
77
|
- config/routes.rb
|
78
78
|
- db/migrate/20171107030047_add_user_logs_table.rb
|
79
|
+
- lib/generators/installer/USAGE
|
80
|
+
- lib/generators/installer/installer_generator.rb
|
81
|
+
- lib/generators/installer/templates/user_activity.rb
|
82
|
+
- lib/generators/installer/templates/user_activity.yml
|
79
83
|
- lib/tasks/user_activity_tasks.rake
|
80
84
|
- lib/user_activity.rb
|
81
85
|
- lib/user_activity/engine.rb
|
82
86
|
- lib/user_activity/version.rb
|
83
|
-
homepage:
|
87
|
+
homepage: https://github.com/kraiyanat/user_activity
|
84
88
|
licenses:
|
85
89
|
- MIT
|
86
90
|
metadata: {}
|