sinaliza 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: bc89fcab6f596adbd552ed8b28da09bba68fc38afc1d784855ebe95361b077ce
4
- data.tar.gz: eb6b974f6c9701a96b8aca56364e562ace77804aa939c87e5ca808a26efbe7e9
3
+ metadata.gz: d645f68aef485dbc199b994b47c4f3434e89cb9101615d4b2806d0203033a340
4
+ data.tar.gz: 428eed5415abc8bf3f7866e6e4903162e417c0b6eceee8e7a4e233bc7374fdaa
5
5
  SHA512:
6
- metadata.gz: 1d60d7c5c5d669fb061882336df233956bea2fed3517e6a9e95756f27e0e70103e3601f743e27b3e41f85c9b281b6ee26d5ca2ee6fb9482bf52a4a2c278d9f39
7
- data.tar.gz: 7b40ff04f632e503bc099a8cb68c9e75dbdde24680085fa65d882cc2767e7d6426ab8ec07dfec667fa3b65e03f28314a3df0c69ebde6a0cdd4b0fb79e24c3d50
6
+ metadata.gz: d03113b99053374a9b758acc715ed5f370aa7a3bef568d782c5abfaf7b109b7255d3f0586c26fd74d436635bb74132d03d3d9fa525897e739bce8a0be0b5acc5
7
+ data.tar.gz: 5ff4559f655c0e3182f0d7ad4170326bae7cae2b8736f70318bd84f8331dacbf8bdda8616743d2c632ebc0c2c734d203e2a89997c5104bbea151b66d22338938
data/README.md CHANGED
@@ -154,6 +154,61 @@ Events are recorded with `source: "controller"`. Request context (IP address, us
154
154
 
155
155
  The actor is resolved by calling the method defined in `Sinaliza.configuration.actor_method` (default: `current_user`).
156
156
 
157
+ ### Interceptors
158
+
159
+ Interceptors let you automatically record events whenever a specific method is called — without modifying the original code. They are stored in the database and can be managed at runtime through the dashboard or programmatically.
160
+
161
+ ```ruby
162
+ # Create an interceptor that tracks every call to User#send_welcome_email
163
+ Sinaliza::Interceptor.create!(
164
+ target_class: "User",
165
+ method_name: "send_welcome_email",
166
+ method_type: "instance",
167
+ event_name: "user.welcome_email_sent"
168
+ )
169
+
170
+ # Track a class method
171
+ Sinaliza::Interceptor.create!(
172
+ target_class: "Report",
173
+ method_name: "generate_monthly",
174
+ method_type: "class",
175
+ event_name: "report.monthly_generated"
176
+ )
177
+ ```
178
+
179
+ Each interceptor can optionally capture:
180
+
181
+ | Option | Description | Default |
182
+ |--------------------------|------------------------------------------|---------|
183
+ | `capture_args` | Log method arguments in metadata | `false` |
184
+ | `capture_return` | Log the return value in metadata | `false` |
185
+ | `capture_execution_time` | Log execution time (ms) in metadata | `false` |
186
+
187
+ ```ruby
188
+ # Interceptor with full instrumentation
189
+ Sinaliza::Interceptor.create!(
190
+ target_class: "PaymentGateway",
191
+ method_name: "charge",
192
+ method_type: "instance",
193
+ event_name: "payment.charged",
194
+ capture_args: true,
195
+ capture_return: true,
196
+ capture_execution_time: true
197
+ )
198
+ ```
199
+
200
+ Interceptors can be toggled on and off without removing them:
201
+
202
+ ```ruby
203
+ interceptor = Sinaliza::Interceptor.find_by(event_name: "user.welcome_email_sent")
204
+ interceptor.deactivate! # stops recording events
205
+ interceptor.activate! # resumes recording events
206
+ ```
207
+
208
+ Events recorded by interceptors have `source: "interceptor"`.
209
+
210
+ The dashboard includes an **Interceptors** section where you can create, edit, toggle, and delete interceptors through a web interface.
211
+
157
212
  ### Query scopes
158
213
 
159
214
  ```ruby
@@ -188,15 +243,31 @@ The engine mounts a monitor dashboard at your chosen path. It provides:
188
243
 
189
244
  ### Protecting the dashboard
190
245
 
191
- The gem does not include authentication. Protect access via route constraints in your host app:
246
+ The gem does not include authentication. Protect access via route constraints in your host app.
247
+
248
+ **With Devise:**
192
249
 
193
250
  ```ruby
194
251
  # config/routes.rb
195
252
  authenticate :user, ->(u) { u.admin? } do
196
253
  mount Sinaliza::Engine => "/sinaliza"
197
254
  end
255
+ ```
256
+
257
+ **Without Devise:**
258
+
259
+ ```ruby
260
+ # app/constraints/admin_constraint.rb
261
+ class AdminConstraint
262
+ def matches?(request)
263
+ user_id = request.session[:user_id]
264
+ return false unless user_id
265
+
266
+ User.find_by(id: user_id)&.admin?
267
+ end
268
+ end
198
269
 
199
- # or with a simple constraint
270
+ # config/routes.rb
200
271
  mount Sinaliza::Engine => "/sinaliza", constraints: AdminConstraint.new
201
272
  ```
202
273