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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b1dd7fd849ef15afaf23f15e523e2d175abc6d22907eb0e066c81322f81fc47
4
- data.tar.gz: 843136aa33a27f4210a108978c2e6c3e9a662e84401d25467d8fb3cf5015b61d
3
+ metadata.gz: 370d0ce9fe01fc27c47eca4f4923a26f161ea8a608a8a952f509eedec23c2605
4
+ data.tar.gz: d21f7d3a2d6c91f2e0f30ed6a42500483c807edc895e972505f97f2c1326851f
5
5
  SHA512:
6
- metadata.gz: 4b5b5ed21b73626718b412f45dbc366f3783b69a67e406f2dfb4dbf833263dd3cce7b5b4336ad2171fda3d93027afe0920fa437334f26a94991e374f8c3ddb36
7
- data.tar.gz: '0418f73fc089f5b58bc159d0950cf3448946fa4bbde9f0eb0b0779cbe9f4fb8f29eecc01f7ed2359d1fb8637e7551a0c973801ef3d5d2e5fbff8d4bfd099eaca'
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` for all the decoratables.
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` to exclude methods from being decorated automagically.
61
+ - `Magic::Decorator::Base.undecorated`
62
+ to exclude methods from being decorated automagically.
51
63
 
52
64
  #### Default decorators
53
65
 
54
- - `EnumerableDecorator` to decorate `Enumerable`s.
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` — a basic decorator class.
65
- - `Magic::Decoratable` to be included in decoratable classes.
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
  ![GitHub Actions Workflow Status](
4
4
  https://img.shields.io/github/actions/workflow/status/Alexander-Senko/magic-decorator/ci.yml
5
5
  )
6
- ![Code Climate maintainability](
7
- https://img.shields.io/codeclimate/maintainability-percentage/Alexander-Senko/magic-decorator
6
+ [![Maintainability](
7
+ https://qlty.sh/gh/Alexander-Senko/projects/magic-decorator/maintainability.svg
8
+ )](
9
+ https://qlty.sh/gh/Alexander-Senko/projects/magic-decorator
8
10
  )
9
- ![Code Climate coverage](
10
- https://img.shields.io/codeclimate/coverage/Alexander-Senko/magic-decorator
11
+ [![Code Coverage](
12
+ https://qlty.sh/gh/Alexander-Senko/projects/magic-decorator/coverage.svg
13
+ )](
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’s not meant to be a _presenter_.
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's Gemfile by executing:
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 lookup.
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'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).
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).
@@ -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
- extend ActiveSupport::Concern
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
- Gem::Author ||= Struct.new(
4
- :name,
5
- :email,
6
- :github,
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
- AUTHORS = [
14
- Gem::Author.new(
15
- name: 'Alexander Senko',
16
- email: 'Alexander.Senko@gmail.com',
17
- github: 'Alexander-Senko',
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
@@ -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 _1 } if
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
- _1.set_backtrace error.backtrace[2..] # FIXME: use `backtrace_locations` with Ruby 3.4+
60
+ it.set_backtrace error.backtrace_locations[2...]
58
61
  }
59
62
  end
60
63
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Magic
4
4
  module Decorator
5
- VERSION = '1.0.2'
5
+ VERSION = '1.1.0'
6
6
  end
7
7
  end
@@ -1,7 +1,5 @@
1
1
  module Magic
2
2
  module Decoratable
3
- def self.classes: () -> Array[Class]
4
-
5
3
  def decorate: () -> Decorator?
6
4
  def decorate!: () -> Decorator
7
5
  def decorated: () -> (Decorator | self)
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.2
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
- name: magic-lookup
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '0'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: '0'
26
- - !ruby/object:Gem::Dependency
27
- name: activesupport
28
- requirement: !ruby/object:Gem::Requirement
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
- - ".rspec"
49
- - ".rubocop.yml"
50
- - CHANGELOG.md
51
- - CODE_OF_CONDUCT.md
52
- - LICENSE.txt
53
- - README.md
54
- - Rakefile
55
- - lib/enumerable_decorator.rb
56
- - lib/magic/decoratable.rb
57
- - lib/magic/decorator.rb
58
- - lib/magic/decorator/authors.rb
59
- - lib/magic/decorator/base.rb
60
- - lib/magic/decorator/version.rb
61
- - sig/enumerable_decorator.rbs
62
- - sig/gem.rbs
63
- - sig/magic/decoratable.rbs
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.2/CHANGELOG.md
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
- - !ruby/object:Gem::Version
80
- version: '3.2'
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
- - !ruby/object:Gem::Version
85
- version: '0'
68
+ -
69
+ - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
86
72
  requirements: []
87
- rubygems_version: 3.7.0.dev
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
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,7 +0,0 @@
1
- inherit_from:
2
- - https://github.com/Alexander-Senko/Alexander-Senko/raw/refs/heads/main/.rubocop.yml
3
- - https://github.com/Alexander-Senko/Alexander-Senko/raw/refs/heads/main/.rubocop-rspec.yml
4
-
5
- plugins:
6
- - rubocop-rspec
7
- - rubocop-rake
data/sig/gem.rbs DELETED
@@ -1,5 +0,0 @@
1
- module Gem
2
- class Author
3
- def github_url: () -> String?
4
- end
5
- end