action_trace 0.2.0 → 0.3.0

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: e1ffc77c240d4ab390847ceb3bcaf692655b9e10cdfb46371c4cdc3188e49313
4
- data.tar.gz: 72e721d26724869b7d2cbd4afef6d0ae5b54609615d779ef974e05ebf21d5d56
3
+ metadata.gz: ac6e3bcd7ddba0d325500935c892b7832116e9f53035b352e757e258fb5b28d4
4
+ data.tar.gz: ddc86843cab5355f2c08b8134048b9d2e6bb00771112570ae037b44a59ca4e4e
5
5
  SHA512:
6
- metadata.gz: 26dbcdfbe1bc91a5ebec2f55e1f3e6d8cc7a31305998a3092f6c29b2f96237c7e7707c88cdd8c87e7dc1560a453b91df3fb23b4493d8e9078ff18fdba8d9b65b
7
- data.tar.gz: e2523e6faa5dc44f365db5e9ba75b99a7f772587b2815ae2592be3e621a2015ba6cd89a4cec64b16a319ebd34fb381fa4209e8448eb4b88c0def335bc27f86de
6
+ metadata.gz: 8f4a13e9befd1d7a05e99acd17cbb3521004cdc4e2ede8e2d0fc9f49f2c176f45a7d20a7a280fc017895927c6e69513b744a479350a109359537927b6067cfc2
7
+ data.tar.gz: ab8913e299894c6c8868384e96a1056d859ae0368e85eb214c57e745808eddad16889f1cf7290b24f0a1afc4ae578c666994461f5ccf5008fa98cd253be1ce73
data/README.md CHANGED
@@ -1,9 +1,8 @@
1
1
  # ActionTrace
2
2
 
3
- ActionTrace is a Rails engine that consolidates user interaction tracking into a single integration point.
4
- It glues together [public_activity](https://github.com/chaps-io/public_activity), [ahoy_matey](https://github.com/ankane/ahoy), [paper_trail](https://github.com/paper-trail-gem/paper_trail), and [discard](https://github.com/jhawthorn/discard) so you don't have to configure each one individually.
3
+ [![Gem Version](https://badge.fury.io/rb/action_trace.svg)](https://rubygems.org/gems/action_trace)
5
4
 
6
- ## What it tracks
5
+ ActionTrace is a Rails engine that consolidates user interaction tracking into a single integration point. Instead of configuring [public_activity](https://github.com/chaps-io/public_activity), [ahoy_matey](https://github.com/ankane/ahoy), [paper_trail](https://github.com/paper-trail-gem/paper_trail), and [discard](https://github.com/jhawthorn/discard) individually, ActionTrace wires them together and exposes a unified activity log with a ready-to-use UI.
7
6
 
8
7
  | Source | Description | Backed by |
9
8
  |---|---|---|
@@ -14,6 +13,8 @@ It glues together [public_activity](https://github.com/chaps-io/public_activity)
14
13
  | `session_start` | User session begun | ahoy_matey (visit) |
15
14
  | `session_end` | User logged out | ahoy_matey (event) |
16
15
 
16
+ ---
17
+
17
18
  ## Installation
18
19
 
19
20
  Add to your Gemfile:
@@ -30,18 +31,16 @@ rails generate action_trace:install
30
31
  rails db:migrate
31
32
  ```
32
33
 
33
- The installer runs the setup generators for all four gems and creates `config/initializers/action_trace.rb`.
34
+ The installer runs the setup generators for all four underlying gems and creates `config/initializers/action_trace.rb`.
34
35
 
35
36
  ### Skipping already-installed gems
36
37
 
37
- If one or more of the underlying gems is already set up, pass `--skip-*` flags:
38
+ If one or more of the underlying gems is already configured, pass `--skip-*` flags:
38
39
 
39
40
  ```bash
40
41
  rails generate action_trace:install --skip-ahoy --skip-paper-trail
41
42
  ```
42
43
 
43
- Available flags:
44
-
45
44
  | Flag | Skips |
46
45
  |---|---|
47
46
  | `--skip-ahoy` | `ahoy:install` |
@@ -64,38 +63,54 @@ GET /action_trace/activity_logs
64
63
  POST /action_trace/activity_logs/filter
65
64
  ```
66
65
 
67
- The controller inherits from the host app's `ApplicationController`. Authentication and authorization are not enforced by default — copy the controller with the generator and uncomment the relevant lines for your setup (e.g. Devise's `authenticate_user!`, CanCanCan's `load_and_authorize_resource`).
66
+ ### Copy views and controller (optional)
68
67
 
69
- ## Configuration
68
+ ActionTrace ships minimal default views that work out of the box. Copy them into your app to customise the UI:
70
69
 
71
- `config/initializers/action_trace.rb` is generated automatically. Available options:
70
+ ```bash
71
+ # Copy views only
72
+ rails generate action_trace:views
72
73
 
73
- ```ruby
74
- ActionTrace.configure do |config|
75
- # Controller names to exclude from page_visit tracking (default: [])
76
- config.excluded_controllers = %w[health_checks status]
74
+ # Copy views and controller
75
+ rails generate action_trace:views --controller
76
+ ```
77
77
 
78
- # Action names to exclude from page_visit tracking (default: [])
79
- config.excluded_actions = %w[ping]
78
+ Views are placed in `app/views/action_trace/activity_logs/`. Rails will use your copies instead of the engine defaults.
80
79
 
81
- # The user model class name used to resolve company filtering
82
- # for PublicActivity::Activity, Ahoy::Visit and Ahoy::Event (default: 'User')
83
- config.user_class = 'User'
80
+ The `--controller` flag also copies `ActivityLogsController` to `app/controllers/action_trace/activity_logs_controller.rb`. The file includes commented-out lines for Devise and CanCanCan authentication — uncomment what applies to your setup or replace with your own auth logic.
84
81
 
85
- # How long to retain activity records before purging (default: 1.year)
86
- config.log_retention_period = 6.months
82
+ > **Note:** once you copy the controller, the engine's version is no longer used. Future updates to the engine's controller will not be applied automatically — keep that in mind when upgrading.
83
+
84
+ ---
85
+
86
+ ## Usage
87
+
88
+ ### Models — tracking data changes
89
+
90
+ Include `ActionTrace::DataTrackable` in any ActiveRecord model you want to track:
91
+
92
+ ```ruby
93
+ class Document < ApplicationRecord
94
+ include ActionTrace::DataTrackable
87
95
  end
88
96
  ```
89
97
 
90
- > `user_class` must have a `company_id` column. ActionTrace uses it to filter
91
- > activity records through the user when filtering by company (since those
92
- > models store the user reference rather than a direct `company_id`).
98
+ This records a `public_activity` event on every `create`, `update`, and `destroy`, linked to the current user (via `PublicActivity.get_controller`) and, when paper_trail is active, to the corresponding version.
93
99
 
94
- ## Usage
100
+ For paper_trail versioning to work, the model also needs `has_paper_trail`:
95
101
 
96
- ### Track page visits — controller concern
102
+ ```ruby
103
+ class Document < ApplicationRecord
104
+ include ActionTrace::DataTrackable
105
+ has_paper_trail
106
+ end
107
+ ```
108
+
109
+ For soft-delete tracking with discard, add `include Discard::Model` alongside `DataTrackable`. The `data_destroy` event is still recorded via the `before_destroy` callback.
97
110
 
98
- Include `ActivityTrackable` in any controller (or `ApplicationController`):
111
+ ### Controllers tracking page visits and sessions
112
+
113
+ Include `ActivityTrackable` in any controller (or `ApplicationController`) to track page visits:
99
114
 
100
115
  ```ruby
101
116
  class ApplicationController < ActionController::Base
@@ -103,34 +118,32 @@ class ApplicationController < ActionController::Base
103
118
  end
104
119
  ```
105
120
 
106
- This adds an `after_action :track_action` that records a `page_visit` event via Ahoy for every successful request made by a logged-in user.
121
+ This adds an `after_action :track_action` that records a `page_visit` event via Ahoy for every successful request made by a logged-in user. It also includes `PublicActivity::StoreController`, which makes the current controller available to model callbacks so that data events can be linked to the right user.
107
122
 
108
- To record a session end on logout, call `track_session_end` in your sessions controller before clearing the session:
123
+ To skip tracking on a specific controller that inherits from `ApplicationController`:
109
124
 
110
125
  ```ruby
111
- class SessionsController < Devise::SessionsController
112
- def destroy
113
- track_session_end
114
- super
115
- end
126
+ class HealthChecksController < ApplicationController
127
+ skip_after_action :track_action
116
128
  end
117
129
  ```
118
130
 
119
- ### Track model changes model concern
120
-
121
- Include `ActionTrace::DataTrackable` in any ActiveRecord model:
131
+ To record a session end on logout, call `track_session_end` before clearing the session:
122
132
 
123
133
  ```ruby
124
- class Document < ApplicationRecord
125
- include ActionTrace::DataTrackable
134
+ class SessionsController < Devise::SessionsController
135
+ def destroy
136
+ track_session_end
137
+ super
138
+ end
126
139
  end
127
140
  ```
128
141
 
129
- This records a `public_activity` event on every `create`, `update`, and `destroy`, linked to the current user (via `PublicActivity.get_controller`) and, when paper_trail is active, to the corresponding version.
142
+ The engine's `ActivityLogsController` inherits from the host app's `ApplicationController`. Authentication and authorization are not enforced by default — copy the controller with the generator and uncomment the relevant lines for your setup (e.g. Devise's `authenticate_user!`, CanCanCan's `load_and_authorize_resource`).
130
143
 
131
- ### Query activity logs
144
+ ### Querying activity logs directly
132
145
 
133
- Use `ActionTrace::FetchActivityLogs` directly to fetch and paginate unified activity:
146
+ Use `ActionTrace::FetchActivityLogs` to fetch and paginate the unified activity log programmatically:
134
147
 
135
148
  ```ruby
136
149
  result = ActionTrace::FetchActivityLogs.call(
@@ -163,43 +176,39 @@ Each `ActionTrace::ActivityLog` exposes:
163
176
  | `trackable` | ActiveRecord object | The changed record (data events only) |
164
177
  | `trackable_type` | String | Class name of the changed record |
165
178
 
166
- #### Presenter helpers
167
-
168
- `ActionTrace::ActivityLog` also provides:
179
+ Presenter helpers are also available on each log:
169
180
 
170
181
  ```ruby
171
- log.icon # => 'fas fa-pencil-alt'
172
- log.color # => 'text-primary'
182
+ log.icon # => 'fas fa-pencil-alt'
183
+ log.color # => 'text-primary'
173
184
  log.data_change? # => true / false
174
185
  log.page_visit? # => true / false
175
- # … (data_create?, data_destroy?, session_start?)
186
+ # data_create?, data_destroy?, session_start?, session_end?
176
187
  ```
177
188
 
178
- ## Customizing views and controller
179
-
180
- ActionTrace ships minimal default views for `activity_logs#index`. These work out of the box but are intentionally bare — copy them into your app to customize the UI.
189
+ ### Configuration
181
190
 
182
- ### Copy views
191
+ `config/initializers/action_trace.rb` is generated automatically. Available options:
183
192
 
184
- ```bash
185
- rails generate action_trace:views
186
- ```
193
+ ```ruby
194
+ ActionTrace.configure do |config|
195
+ # Controller names to exclude from page_visit tracking (default: [])
196
+ config.excluded_controllers = %w[health_checks status]
187
197
 
188
- This copies the engine views to `app/views/action_trace/activity_logs/` in your application. Rails will use your copies instead of the engine defaults.
198
+ # Action names to exclude from page_visit tracking (default: [])
199
+ config.excluded_actions = %w[ping]
189
200
 
190
- ### Copy views and controller
201
+ # The user model class name used to resolve company filtering (default: 'User')
202
+ config.user_class = 'User'
191
203
 
192
- ```bash
193
- rails generate action_trace:views --controller
204
+ # How long to retain activity records before purging (default: 1.year)
205
+ config.log_retention_period = 6.months
206
+ end
194
207
  ```
195
208
 
196
- Also copies `ActivityLogsController` to `app/controllers/action_trace/activity_logs_controller.rb`. The file includes commented-out lines for Devise and CanCanCan uncomment what applies to your setup, or replace with your own auth logic.
197
-
198
- > After copying the controller, the engine's version is no longer used. Any future updates to the engine's controller will not be applied automatically — keep that in mind when upgrading.
209
+ > `user_class` must have a `company_id` column. ActionTrace uses it to filter activity records by company (since Ahoy and PublicActivity store the user reference rather than a direct `company_id`).
199
210
 
200
- ## Maintenance
201
-
202
- ### Purge old records
211
+ ### Purging old records
203
212
 
204
213
  `ActionTrace::PurgeActivityLogJob` removes all `PublicActivity::Activity`, `Ahoy::Event`, and `Ahoy::Visit` records older than `log_retention_period` (default: 1 year). Schedule it with your preferred job scheduler:
205
214
 
@@ -208,6 +217,8 @@ Also copies `ActivityLogsController` to `app/controllers/action_trace/activity_l
208
217
  ActionTrace::PurgeActivityLogJob.perform_later
209
218
  ```
210
219
 
220
+ ---
221
+
211
222
  ## License
212
223
 
213
224
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActionTrace
4
4
  class FetchActivityLogs
5
- include Interactor::Organizer
5
+ include ::Interactor::Organizer
6
6
 
7
7
  organize ActionTrace::InitializeContext,
8
8
  ActionTrace::FetchDataChanges,
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActionTrace
4
4
  class FetchDataChanges
5
- include Interactor
5
+ include ::Interactor
6
6
  include ActivityLogFetchable
7
7
 
8
8
  def call
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActionTrace
4
4
  class FetchPageVisits
5
- include Interactor
5
+ include ::Interactor
6
6
  include ActivityLogFetchable
7
7
 
8
8
  def call
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActionTrace
4
4
  class FetchSessionStarts
5
- include Interactor
5
+ include ::Interactor
6
6
  include ActivityLogFetchable
7
7
 
8
8
  def call
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActionTrace
4
4
  class InitializeContext
5
- include Interactor
5
+ include ::Interactor
6
6
 
7
7
  def call
8
8
  filters = context.filters || {}
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ActionTrace
4
4
  class MergeAndFormatResults
5
- include Interactor
5
+ include ::Interactor
6
6
  include ActivityLogFetchable
7
7
 
8
8
  def call
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActionTrace
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/action_trace.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'interactor'
3
4
  require 'action_trace/version'
4
5
  require 'action_trace/configuration'
5
6
  require 'action_trace/engine'
@@ -22,7 +22,7 @@ module ActionTrace
22
22
  return unless options[:controller]
23
23
 
24
24
  copy_file(
25
- File.expand_path('../../../../../app/controllers/action_trace/activity_logs_controller.rb', __dir__),
25
+ File.expand_path('../../../../app/controllers/action_trace/activity_logs_controller.rb', __dir__),
26
26
  'app/controllers/action_trace/activity_logs_controller.rb'
27
27
  )
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_trace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gimbaro
@@ -293,7 +293,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
293
  - !ruby/object:Gem::Version
294
294
  version: '0'
295
295
  requirements: []
296
- rubygems_version: 3.7.2
296
+ rubygems_version: 4.0.8
297
297
  specification_version: 4
298
298
  summary: A Rails engine that consolidates user interaction tracking into a single
299
299
  integration