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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 570aafea45f410b73687c1369cad33444d88050a
4
- data.tar.gz: 5b51b03da704c47f3d434ed769cc05b043f696c7
3
+ metadata.gz: ca0ef675a19edb56bccd4933aeb5a52f5afc778c
4
+ data.tar.gz: c14aca3b123c5b806626ac68d988f8f73ec49bb1
5
5
  SHA512:
6
- metadata.gz: 9c8aa9f7a8097d7dd04b717836b1ff8a3dde4072aec9721c5c9f19d358f1843562624e1426c7aef9eccf18d5c5a980519cd4ce8e4b1be4af7058bcaaf22ab807
7
- data.tar.gz: 0c584653f8d72004d0fd57b9bb5e4d21c390648a93556f9ec1f65a5ab39a3546902d56a81682c247fff8ed7e59fa431ee3649a017c360d4d1777ac2936d1f2f0
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,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate installer Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -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
- @current_user || Struct.new(:name, :id).new("anonymus", "")
27
+ Struct.new(:name, :id).new("anonymus", "")
11
28
  end
12
29
 
13
30
  def activity_for_user_activity(controller, method)
14
- activity_hash = {}
15
- activity_hash[["aa", "bb"]] = "cc"
16
-
17
- activity_hash[[controller.to_s, method.to_s]].to_s
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("aa", "bb"),
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
@@ -1,3 +1,3 @@
1
1
  module UserActivity
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  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.0
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-21 00:00:00.000000000 Z
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.4
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.4
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: {}