magic-decorator 1.0.2 → 1.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/CHANGELOG.md +20 -5
- data/README.md +12 -8
- data/lib/magic/decoratable.rb +2 -14
- data/lib/magic/decorator/authors.rb +10 -18
- data/lib/magic/decorator/base.rb +6 -3
- data/lib/magic/decorator/version.rb +1 -1
- data/sig/magic/decoratable.rbs +0 -2
- metadata +50 -64
- data/.rspec +0 -3
- data/.rubocop.yml +0 -7
- data/sig/gem.rbs +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 370d0ce9fe01fc27c47eca4f4923a26f161ea8a608a8a952f509eedec23c2605
|
|
4
|
+
data.tar.gz: d21f7d3a2d6c91f2e0f30ed6a42500483c807edc895e972505f97f2c1326851f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cfc3ca9c768a3550cf6fad72dc986db4d8a704f385d9d7cd2fa80f29ed7809f18c68b1fcdca394459bce86be506e749f7d3aad2a588256842359c99408dc2364
|
|
7
|
+
data.tar.gz: 44126c4a06cb32343f98abb975e0327cf518ea17860e487f7a30939e42be5d36f642af19e01d8d5d1df3df1431467916c0f5d362cd038e06bc8b75af023aa071
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [1.1.0] — 2026-09-29
|
|
2
|
+
|
|
3
|
+
Moved to Magic Lookup 1.0.
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Extracted implementation of `Magic::Decoratable.classes` to `Magic::Lookup::Scope`.
|
|
8
|
+
- Moved to Ruby 3.4+.
|
|
9
|
+
|
|
10
|
+
|
|
1
11
|
## [1.0.2] — 2026-05-05
|
|
2
12
|
|
|
3
13
|
Works with Ruby 4+.
|
|
@@ -28,7 +38,8 @@ This release marks the gem to be stable enough.
|
|
|
28
38
|
### Added
|
|
29
39
|
|
|
30
40
|
- Improved extendability: one may override `Magic::Decoratable#decorator_base` to be used for lookups.
|
|
31
|
-
- `Magic::Decoratable.classes`
|
|
41
|
+
- `Magic::Decoratable.classes`
|
|
42
|
+
for all the decoratables.
|
|
32
43
|
|
|
33
44
|
### Fixed
|
|
34
45
|
|
|
@@ -47,11 +58,13 @@ This release marks the gem to be stable enough.
|
|
|
47
58
|
|
|
48
59
|
### Added
|
|
49
60
|
|
|
50
|
-
- `Magic::Decorator::Base.undecorated`
|
|
61
|
+
- `Magic::Decorator::Base.undecorated`
|
|
62
|
+
to exclude methods from being decorated automagically.
|
|
51
63
|
|
|
52
64
|
#### Default decorators
|
|
53
65
|
|
|
54
|
-
- `EnumerableDecorator`
|
|
66
|
+
- `EnumerableDecorator`
|
|
67
|
+
to decorate `Enumerable`s.
|
|
55
68
|
- enables _splat_ operator: `*decorated` ,
|
|
56
69
|
- enables _double-splat_ operator: `**decorated`,
|
|
57
70
|
- enumerating methods yield decorated items.
|
|
@@ -61,8 +74,10 @@ This release marks the gem to be stable enough.
|
|
|
61
74
|
|
|
62
75
|
### Added
|
|
63
76
|
|
|
64
|
-
- `Magic::Decorator::Base`
|
|
65
|
-
|
|
77
|
+
- `Magic::Decorator::Base`
|
|
78
|
+
— a basic decorator class.
|
|
79
|
+
- `Magic::Decoratable`
|
|
80
|
+
to be included in decoratable classes.
|
|
66
81
|
- `#decorate`,
|
|
67
82
|
- `#decorate!`,
|
|
68
83
|
- `#decorated`,
|
data/README.md
CHANGED
|
@@ -3,21 +3,25 @@
|
|
|
3
3
|

|
|
6
|
-
](
|
|
9
|
+
https://qlty.sh/gh/Alexander-Senko/projects/magic-decorator
|
|
8
10
|
)
|
|
9
|
-
](
|
|
14
|
+
https://qlty.sh/gh/Alexander-Senko/projects/magic-decorator
|
|
11
15
|
)
|
|
12
16
|
|
|
13
17
|
A bit of history:
|
|
14
18
|
this gem was inspired by digging deeper into [Draper](https://github.com/drapergem/draper) with an eye on a refactoring.
|
|
15
19
|
|
|
16
|
-
It implements a general decorator logic. It
|
|
20
|
+
It implements a general decorator logic. It is not meant to be a _presenter_.
|
|
17
21
|
|
|
18
22
|
## Installation
|
|
19
23
|
|
|
20
|
-
Install the gem and add to the application
|
|
24
|
+
Install the gem and add to the application’s Gemfile by executing:
|
|
21
25
|
|
|
22
26
|
$ bundle add magic-decorator
|
|
23
27
|
|
|
@@ -65,7 +69,7 @@ One can test for the object is actually decorated with `#decorated?`.
|
|
|
65
69
|
|
|
66
70
|
### Extending decorator logic
|
|
67
71
|
|
|
68
|
-
When extending `Magic::Decoratable`, one may override `#decorator_base` to be used for
|
|
72
|
+
When extending `Magic::Decoratable`, one may override `#decorator_base` to be used for lookups.
|
|
69
73
|
|
|
70
74
|
```ruby
|
|
71
75
|
class Special::Decorator < Magic::Decorator::Base
|
|
@@ -226,4 +230,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
226
230
|
|
|
227
231
|
## Code of Conduct
|
|
228
232
|
|
|
229
|
-
Everyone interacting in the Magic Decorator project
|
|
233
|
+
Everyone interacting in the Magic Decorator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Alexander-Senko/magic-decorator/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/magic/decoratable.rb
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'active_support/concern'
|
|
4
|
-
|
|
5
3
|
module Magic
|
|
6
4
|
module Decoratable
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class_methods do
|
|
10
|
-
def classes
|
|
11
|
-
ObjectSpace.each_object(Class)
|
|
12
|
-
.select { _1 < self }
|
|
13
|
-
.reject(&:singleton_class?)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
extend ClassMethods
|
|
5
|
+
include Lookup::Scope
|
|
18
6
|
|
|
19
7
|
def decorate = decorator&.new self
|
|
20
8
|
def decorate! = decorate || raise(Lookup::Error.for self, decorator_base)
|
|
@@ -24,6 +12,6 @@ module Magic
|
|
|
24
12
|
private
|
|
25
13
|
|
|
26
14
|
def decorator = decorator_base.for self.class
|
|
27
|
-
def decorator_base = Decorator
|
|
15
|
+
def decorator_base = Decorator::Base
|
|
28
16
|
end
|
|
29
17
|
end
|
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
) do
|
|
8
|
-
def github_url = github && "https://github.com/#{github}"
|
|
3
|
+
begin
|
|
4
|
+
require 'rubygems/author'
|
|
5
|
+
rescue LoadError
|
|
6
|
+
require_relative '../../../vendor/gems/rubygems-author/lib/rubygems/author'
|
|
9
7
|
end
|
|
10
8
|
|
|
11
9
|
module Magic
|
|
12
10
|
module Decorator
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
class << AUTHORS
|
|
22
|
-
def names = filter_map &:name
|
|
23
|
-
def emails = filter_map &:email
|
|
24
|
-
def github_url = filter_map(&:github_url).first
|
|
11
|
+
class Author < Gem::Author # :nodoc:
|
|
12
|
+
new(
|
|
13
|
+
name: 'Alexander Senko',
|
|
14
|
+
email: 'Alexander.Senko@gmail.com',
|
|
15
|
+
github: 'Alexander-Senko',
|
|
16
|
+
)
|
|
25
17
|
end
|
|
26
18
|
end
|
|
27
19
|
end
|
data/lib/magic/decorator/base.rb
CHANGED
|
@@ -11,14 +11,17 @@ module Magic
|
|
|
11
11
|
class << self
|
|
12
12
|
def name_for(object_class) = "#{object_class}Decorator"
|
|
13
13
|
|
|
14
|
+
def to_s = super
|
|
15
|
+
.delete_suffix('::Base')
|
|
16
|
+
|
|
14
17
|
private
|
|
15
18
|
|
|
16
19
|
def undecorated method, *methods
|
|
17
|
-
return [ method, *methods ].map { undecorated
|
|
20
|
+
return [ method, *methods ].map { undecorated it } if
|
|
18
21
|
methods.any?
|
|
19
22
|
return undecorated *method if
|
|
20
23
|
method.is_a? Array
|
|
21
|
-
raise TypeError, "#{method} is not a symbol nor a string" unless
|
|
24
|
+
raise TypeError, "#{method} is not a symbol, nor a string" unless
|
|
22
25
|
method in Symbol | String
|
|
23
26
|
|
|
24
27
|
class_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
@@ -54,7 +57,7 @@ module Magic
|
|
|
54
57
|
|
|
55
58
|
receiver: __getobj__
|
|
56
59
|
).tap {
|
|
57
|
-
|
|
60
|
+
it.set_backtrace error.backtrace_locations[2...]
|
|
58
61
|
}
|
|
59
62
|
end
|
|
60
63
|
end
|
data/sig/magic/decoratable.rbs
CHANGED
metadata
CHANGED
|
@@ -1,90 +1,76 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: magic-decorator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Alexander Senko
|
|
7
|
+
- Alexander Senko
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
-
- !ruby/object:Gem::Dependency
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
- !ruby/object:Gem::
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
requirements:
|
|
30
|
-
- - ">="
|
|
31
|
-
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0'
|
|
33
|
-
type: :runtime
|
|
34
|
-
prerelease: false
|
|
35
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
-
requirements:
|
|
37
|
-
- - ">="
|
|
38
|
-
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0'
|
|
40
|
-
description: 'SimpleDelegator on steroids: automatic delegation, decorator class inference,
|
|
41
|
-
etc.'
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: magic-lookup
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
-
|
|
17
|
+
- ~>
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: "1.0"
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
-
|
|
25
|
+
- ~>
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
version: "1.0"
|
|
28
|
+
description: "SimpleDelegator on steroids: automatic delegation, decorator class inference, etc."
|
|
42
29
|
email:
|
|
43
|
-
- Alexander.Senko@gmail.com
|
|
30
|
+
- Alexander.Senko@gmail.com
|
|
44
31
|
executables: []
|
|
45
32
|
extensions: []
|
|
46
33
|
extra_rdoc_files: []
|
|
47
34
|
files:
|
|
48
|
-
-
|
|
49
|
-
-
|
|
50
|
-
-
|
|
51
|
-
-
|
|
52
|
-
-
|
|
53
|
-
-
|
|
54
|
-
-
|
|
55
|
-
- lib/
|
|
56
|
-
- lib/magic/
|
|
57
|
-
- lib/magic/decorator.rb
|
|
58
|
-
- lib/magic/decorator/
|
|
59
|
-
-
|
|
60
|
-
-
|
|
61
|
-
- sig/
|
|
62
|
-
- sig/
|
|
63
|
-
|
|
64
|
-
- sig/magic/decorator.rbs
|
|
65
|
-
- sig/magic/decorator/base.rbs
|
|
66
|
-
homepage: https://github.com/Alexander-Senko/magic-decorator
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- CODE_OF_CONDUCT.md
|
|
37
|
+
- LICENSE.txt
|
|
38
|
+
- README.md
|
|
39
|
+
- Rakefile
|
|
40
|
+
- lib/enumerable_decorator.rb
|
|
41
|
+
- lib/magic/decoratable.rb
|
|
42
|
+
- lib/magic/decorator.rb
|
|
43
|
+
- lib/magic/decorator/authors.rb
|
|
44
|
+
- lib/magic/decorator/base.rb
|
|
45
|
+
- lib/magic/decorator/version.rb
|
|
46
|
+
- sig/enumerable_decorator.rbs
|
|
47
|
+
- sig/magic/decoratable.rbs
|
|
48
|
+
- sig/magic/decorator.rbs
|
|
49
|
+
- sig/magic/decorator/base.rbs
|
|
50
|
+
homepage: "https://github.com/Alexander-Senko/magic-decorator"
|
|
67
51
|
licenses:
|
|
68
|
-
- MIT
|
|
52
|
+
- MIT
|
|
69
53
|
metadata:
|
|
70
|
-
homepage_uri: https://github.com/Alexander-Senko/magic-decorator
|
|
71
|
-
source_code_uri: https://github.com/Alexander-Senko/magic-decorator
|
|
72
|
-
changelog_uri: https://github.com/Alexander-Senko/magic-decorator/blob/v1.0
|
|
54
|
+
homepage_uri: "https://github.com/Alexander-Senko/magic-decorator"
|
|
55
|
+
source_code_uri: "https://github.com/Alexander-Senko/magic-decorator"
|
|
56
|
+
changelog_uri: "https://github.com/Alexander-Senko/magic-decorator/blob/v1.1.0/CHANGELOG.md"
|
|
73
57
|
rdoc_options: []
|
|
74
58
|
require_paths:
|
|
75
|
-
- lib
|
|
59
|
+
- lib
|
|
76
60
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
61
|
requirements:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
-
|
|
63
|
+
- ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: "3.4"
|
|
81
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
67
|
requirements:
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
68
|
+
-
|
|
69
|
+
- ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: "0"
|
|
86
72
|
requirements: []
|
|
87
|
-
rubygems_version:
|
|
73
|
+
rubygems_version: 4.1.0.dev
|
|
88
74
|
specification_version: 4
|
|
89
75
|
summary: Decorators with some internal magic
|
|
90
76
|
test_files: []
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED