solid_callback 3.0.0 → 3.1.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 +4 -4
- data/README.md +29 -11
- data/lib/solid_callback/version.rb +1 -1
- data/mise.toml +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d4868400ada59602777596c75942cdb942d5be9e44ad383d766706ce1bc14b0
|
|
4
|
+
data.tar.gz: 8131d95e2f3c04527216b38c4a030bfcb9e623e6b1912e344fa7fa592237aee0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 11fd8d6357fe2b71c683443f03bb0db6eb45a7467cf048ea5a0a30b06aee63f4a75329cbc39220524828cf596b871c1bdcba781b264bc646f7fa64899cb8818c
|
|
7
|
+
data.tar.gz: 7373f5b5c012a02d8cd6c4dbde06bf25e5bac6ad35591f4e3043245a03dd4b0043f5c201ced775864838d56426b6cd76af56b483996f8320677ba3b2da9b96cd
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/rb/solid_callback)
|
|
4
4
|
[](https://github.com/gklsan/solid_callback/actions/workflows/ruby.yml)
|
|
5
|
-
[](https://badge.fury.io/rb/solid_callback)
|
|
6
6
|
[](https://github.com/gklsan/solid_callback/network)
|
|
7
7
|
[](https://github.com/gklsan/solid_callback/stargazers)
|
|
8
8
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -18,6 +18,10 @@ SolidCallback adds powerful method interception capabilities to your Ruby classe
|
|
|
18
18
|
- 🔒 **Thread-safe**: Safely use in concurrent applications
|
|
19
19
|
- 📝 **Conditional execution**: Run callbacks only when specific conditions are met
|
|
20
20
|
|
|
21
|
+
## Requirements
|
|
22
|
+
|
|
23
|
+
- Ruby >= 3.3.0
|
|
24
|
+
|
|
21
25
|
## Installation
|
|
22
26
|
|
|
23
27
|
Add this line to your application's Gemfile:
|
|
@@ -138,15 +142,13 @@ before_call :notify_admin, if: -> { Rails.env.production? }
|
|
|
138
142
|
|
|
139
143
|
### Skipping Callbacks
|
|
140
144
|
|
|
141
|
-
|
|
145
|
+
Use `except:` to exclude specific methods from a callback:
|
|
142
146
|
|
|
143
147
|
```ruby
|
|
144
148
|
class ApiService
|
|
145
149
|
include SolidCallback
|
|
146
150
|
|
|
147
|
-
before_call :rate_limit
|
|
148
|
-
|
|
149
|
-
skip_callbacks_for :health_check
|
|
151
|
+
before_call :rate_limit, except: [:health_check]
|
|
150
152
|
|
|
151
153
|
def get_data
|
|
152
154
|
# Implementation...
|
|
@@ -159,6 +161,10 @@ class ApiService
|
|
|
159
161
|
end
|
|
160
162
|
```
|
|
161
163
|
|
|
164
|
+
> **Note:** `skip_callbacks_for` is also available on the class, but it currently only
|
|
165
|
+
> records the given method names — it does not yet suppress callback execution. Prefer
|
|
166
|
+
> `except:` (as above) until that's wired up.
|
|
167
|
+
|
|
162
168
|
## Callback Options
|
|
163
169
|
|
|
164
170
|
Each callback method accepts the following options:
|
|
@@ -172,12 +178,24 @@ Each callback method accepts the following options:
|
|
|
172
178
|
|
|
173
179
|
## How It Works
|
|
174
180
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
1.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
+
SolidCallback uses Ruby's metaprogramming to wrap your methods with callback functionality:
|
|
182
|
+
|
|
183
|
+
1. `include SolidCallback` extends your class with the callback registration API and
|
|
184
|
+
hooks into `method_added` so newly defined methods can be wrapped automatically.
|
|
185
|
+
2. `before_call`, `after_call`, and `around_call` just store the callback configuration
|
|
186
|
+
(method name, `only`/`except`/`if`/`unless`) on the class — they don't need to run
|
|
187
|
+
before the target method is defined.
|
|
188
|
+
3. Each time a **public** instance method is defined, it's aliased to
|
|
189
|
+
`_solid_callback_original_<method>` and replaced with a wrapper that runs the
|
|
190
|
+
applicable `before` callbacks, then the `around` chain (which ultimately calls the
|
|
191
|
+
original method), then the applicable `after` callbacks. Private/protected methods
|
|
192
|
+
are left untouched.
|
|
193
|
+
4. Applicability (`only`, `except`, `if`, `unless`) is evaluated per call, against the
|
|
194
|
+
actual instance, so the same callback can behave differently per invocation.
|
|
195
|
+
5. `around_call` callbacks are nested in registration order (the first one registered is
|
|
196
|
+
outermost) and must `yield` to continue the chain, much like Rack middleware.
|
|
197
|
+
6. If a method needs wrapping outside the normal `method_added` flow, call
|
|
198
|
+
`wrap_methods(:method_name, ...)` explicitly.
|
|
181
199
|
|
|
182
200
|
## 📚 Use Cases
|
|
183
201
|
|
data/mise.toml
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
[tools]
|
|
2
|
-
ruby = "4"
|
|
2
|
+
ruby = "3.4.2"
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: solid_callback
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gokul (gklsan)
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-07-07 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: bundler
|
|
@@ -124,14 +124,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
124
124
|
requirements:
|
|
125
125
|
- - ">="
|
|
126
126
|
- !ruby/object:Gem::Version
|
|
127
|
-
version:
|
|
127
|
+
version: 3.3.0
|
|
128
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
requirements:
|
|
130
130
|
- - ">="
|
|
131
131
|
- !ruby/object:Gem::Version
|
|
132
132
|
version: '0'
|
|
133
133
|
requirements: []
|
|
134
|
-
rubygems_version:
|
|
134
|
+
rubygems_version: 3.6.6
|
|
135
135
|
specification_version: 4
|
|
136
136
|
summary: SolidCallback adds powerful method interception capabilities to your Ruby
|
|
137
137
|
classes with near-zero overhead. Clean, flexible, and unobtrusive.
|