magic-decorator 0.3.0 → 1.0.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/CHANGELOG.md +20 -0
- data/README.md +45 -0
- data/lib/magic/decoratable.rb +1 -0
- data/lib/magic/decorator/base.rb +2 -0
- data/lib/magic/decorator/version.rb +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: c39be12629f5b9ec85cdd45ab16d09816dbb5ff3ea7f52c56b6dbf237009ec42
|
4
|
+
data.tar.gz: 34244c6e8bea2cc79d9405ecd74093c563bc74af001b041e17caefa41831834e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd24960b368a753b1137933a06a350dde8f6cb86adcd717cf1d8a064127ddde66d97d1f806ae9d68befa37898b2ad8d557780629412c40886f26ab03aa146176
|
7
|
+
data.tar.gz: e28df69e1bc1d3ad2354db3b20cd89c583ca5f45ea67954c362573eda0140e874c9e1963b7b9126a72d3764096fbbfe0d3d41ad1376cdb41c02d1bcf84c25630
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## [1.0.1] — 2025-05-13
|
2
|
+
|
3
|
+
### Fixed
|
4
|
+
|
5
|
+
- `Magic::Decoratable.classes` shouldn’t include singleton ones.
|
6
|
+
|
7
|
+
|
8
|
+
## [1.0.0] — 2024-11-23
|
9
|
+
|
10
|
+
This release marks the gem to be stable enough.
|
11
|
+
|
12
|
+
> [!NOTE]
|
13
|
+
> Nothing notable was changed in the code since the last version.
|
14
|
+
|
15
|
+
### Documentation
|
16
|
+
|
17
|
+
- Added a section about overriding the defaults.
|
18
|
+
- Added a section about testing.
|
19
|
+
|
20
|
+
|
1
21
|
## [0.3.0] — 2024-10-27
|
2
22
|
|
3
23
|
### Added
|
data/README.md
CHANGED
@@ -165,6 +165,51 @@ It automagically decorates all its decoratable items.
|
|
165
165
|
- enables _double-splat_ operator: `**decorated`,
|
166
166
|
- enumerating methods yield decorated items.
|
167
167
|
|
168
|
+
## Overriding the magic
|
169
|
+
|
170
|
+
When one needs more complicated behavior than the default one or feels like [_explicit is better than implicit_](
|
171
|
+
https://peps.python.org/pep-0020/#the-zen-of-python
|
172
|
+
).
|
173
|
+
|
174
|
+
### Decorator class inference
|
175
|
+
|
176
|
+
One may override `#decorator` for any decoratable class, to be used instead of Magic Lookup.
|
177
|
+
|
178
|
+
- That could be as straightforward as a constant:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
class Guest
|
182
|
+
private
|
183
|
+
|
184
|
+
def decorator = UserDecorator
|
185
|
+
end
|
186
|
+
|
187
|
+
guest.decorate # => instance of UserDecorator
|
188
|
+
```
|
189
|
+
|
190
|
+
- Or, that could be virtually any logic:
|
191
|
+
|
192
|
+
```ruby
|
193
|
+
class User
|
194
|
+
private
|
195
|
+
|
196
|
+
def decorator = admin? ? AdminDecorator : super
|
197
|
+
end
|
198
|
+
|
199
|
+
user.decorate # => instance of UserDecorator
|
200
|
+
admin.decorate # => instance of AdminDecorator
|
201
|
+
```
|
202
|
+
|
203
|
+
## Testing decorators
|
204
|
+
|
205
|
+
Testing a decorator is much like testing any other class.
|
206
|
+
|
207
|
+
To test whether an object is decorated one can use `#decorated?` method.
|
208
|
+
|
209
|
+
> [!NOTE]
|
210
|
+
> A decorated object equals the original one (`object.decorated == object`).
|
211
|
+
> Thus, any existing tests shouldn’t break when the objects being tested get decorated.
|
212
|
+
|
168
213
|
## Development
|
169
214
|
|
170
215
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/magic/decoratable.rb
CHANGED
data/lib/magic/decorator/base.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magic-decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Senko
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 2025-05-13 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: magic-lookup
|
@@ -69,7 +69,7 @@ licenses:
|
|
69
69
|
metadata:
|
70
70
|
homepage_uri: https://github.com/Alexander-Senko/magic-decorator
|
71
71
|
source_code_uri: https://github.com/Alexander-Senko/magic-decorator
|
72
|
-
changelog_uri: https://github.com/Alexander-Senko/magic-decorator/blob/
|
72
|
+
changelog_uri: https://github.com/Alexander-Senko/magic-decorator/blob/v1.0.1/CHANGELOG.md
|
73
73
|
rdoc_options: []
|
74
74
|
require_paths:
|
75
75
|
- lib
|
@@ -84,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
84
|
- !ruby/object:Gem::Version
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
|
-
rubygems_version: 3.6.
|
87
|
+
rubygems_version: 3.6.5
|
88
88
|
specification_version: 4
|
89
89
|
summary: Decorators with some internal magic
|
90
90
|
test_files: []
|