decoor 0.0.1 → 0.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.
data/Gemfile.lock CHANGED
@@ -6,138 +6,54 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (7.1.3.4)
10
- actionview (= 7.1.3.4)
11
- activesupport (= 7.1.3.4)
12
- nokogiri (>= 1.8.5)
13
- racc
14
- rack (>= 2.2.4)
15
- rack-session (>= 1.0.1)
16
- rack-test (>= 0.6.3)
17
- rails-dom-testing (~> 2.2)
18
- rails-html-sanitizer (~> 1.6)
19
- actionview (7.1.3.4)
20
- activesupport (= 7.1.3.4)
21
- builder (~> 3.1)
22
- erubi (~> 1.11)
23
- rails-dom-testing (~> 2.2)
24
- rails-html-sanitizer (~> 1.6)
25
- activesupport (7.1.3.4)
26
- base64
27
- bigdecimal
28
- concurrent-ruby (~> 1.0, >= 1.0.2)
29
- connection_pool (>= 2.2.5)
30
- drb
31
- i18n (>= 1.6, < 2)
32
- minitest (>= 5.1)
33
- mutex_m
34
- tzinfo (~> 2.0)
35
- ast (2.4.2)
36
- base64 (0.2.0)
37
- bigdecimal (3.1.8)
9
+ ansi (1.5.0)
10
+ ast (2.4.3)
38
11
  builder (3.3.0)
39
- concurrent-ruby (1.3.3)
40
- connection_pool (2.4.1)
41
- crass (1.0.6)
42
- diff-lcs (1.5.1)
43
- docile (1.4.0)
44
- drb (2.2.1)
45
- erubi (1.13.0)
46
- i18n (1.14.5)
47
- concurrent-ruby (~> 1.0)
48
- io-console (0.7.2)
49
- irb (1.13.2)
50
- rdoc (>= 4.0.0)
51
- reline (>= 0.4.2)
52
- json (2.7.2)
53
- language_server-protocol (3.17.0.3)
54
- loofah (2.22.0)
55
- crass (~> 1.0.2)
56
- nokogiri (>= 1.12.0)
57
- minitest (5.24.0)
58
- mutex_m (0.2.0)
59
- nokogiri (1.16.6-arm64-darwin)
60
- racc (~> 1.4)
61
- nokogiri (1.16.6-x64-mingw-ucrt)
62
- racc (~> 1.4)
63
- nokogiri (1.16.6-x86_64-darwin)
64
- racc (~> 1.4)
65
- nokogiri (1.16.6-x86_64-linux)
66
- racc (~> 1.4)
67
- parallel (1.25.1)
68
- parser (3.3.3.0)
12
+ docile (1.4.1)
13
+ json (2.12.2)
14
+ language_server-protocol (3.17.0.5)
15
+ lint_roller (1.1.0)
16
+ minitest (5.25.5)
17
+ minitest-reporters (1.7.1)
18
+ ansi
19
+ builder
20
+ minitest (>= 5.0)
21
+ ruby-progressbar
22
+ parallel (1.27.0)
23
+ parser (3.3.8.0)
69
24
  ast (~> 2.4.1)
70
25
  racc
71
- psych (5.1.2)
72
- stringio
73
- racc (1.8.0)
74
- rack (3.1.3)
75
- rack-session (2.0.0)
76
- rack (>= 3.0.0)
77
- rack-test (2.1.0)
78
- rack (>= 1.3)
79
- rackup (2.1.0)
80
- rack (>= 3)
81
- webrick (~> 1.8)
82
- rails-dom-testing (2.2.0)
83
- activesupport (>= 5.0.0)
84
- minitest
85
- nokogiri (>= 1.6)
86
- rails-html-sanitizer (1.6.0)
87
- loofah (~> 2.21)
88
- nokogiri (~> 1.14)
89
- railties (7.1.3.4)
90
- actionpack (= 7.1.3.4)
91
- activesupport (= 7.1.3.4)
92
- irb
93
- rackup (>= 1.0.0)
94
- rake (>= 12.2)
95
- thor (~> 1.0, >= 1.2.2)
96
- zeitwerk (~> 2.6)
26
+ prism (1.4.0)
27
+ racc (1.8.1)
97
28
  rainbow (3.1.1)
98
- rake (13.2.1)
99
- rdoc (6.7.0)
100
- psych (>= 4.0.0)
101
- regexp_parser (2.9.2)
102
- reline (0.5.9)
103
- io-console (~> 0.5)
104
- rexml (3.3.0)
105
- strscan
106
- rspec-core (3.13.0)
107
- rspec-support (~> 3.13.0)
108
- rspec-expectations (3.13.1)
109
- diff-lcs (>= 1.2.0, < 2.0)
110
- rspec-support (~> 3.13.0)
111
- rspec-mocks (3.13.1)
112
- diff-lcs (>= 1.2.0, < 2.0)
113
- rspec-support (~> 3.13.0)
114
- rspec-rails (6.1.3)
115
- actionpack (>= 6.1)
116
- activesupport (>= 6.1)
117
- railties (>= 6.1)
118
- rspec-core (~> 3.13)
119
- rspec-expectations (~> 3.13)
120
- rspec-mocks (~> 3.13)
121
- rspec-support (~> 3.13)
122
- rspec-support (3.13.1)
123
- rubocop (1.64.1)
29
+ rake (13.3.0)
30
+ regexp_parser (2.10.0)
31
+ rexml (3.4.1)
32
+ rubocop (1.77.0)
124
33
  json (~> 2.3)
125
- language_server-protocol (>= 3.17.0)
34
+ language_server-protocol (~> 3.17.0.2)
35
+ lint_roller (~> 1.1.0)
126
36
  parallel (~> 1.10)
127
37
  parser (>= 3.3.0.2)
128
38
  rainbow (>= 2.2.2, < 4.0)
129
- regexp_parser (>= 1.8, < 3.0)
130
- rexml (>= 3.2.5, < 4.0)
131
- rubocop-ast (>= 1.31.1, < 2.0)
39
+ regexp_parser (>= 2.9.3, < 3.0)
40
+ rubocop-ast (>= 1.45.1, < 2.0)
132
41
  ruby-progressbar (~> 1.7)
133
- unicode-display_width (>= 2.4.0, < 3.0)
134
- rubocop-ast (1.31.3)
135
- parser (>= 3.3.1.0)
136
- rubocop-performance (1.21.1)
137
- rubocop (>= 1.48.1, < 2.0)
138
- rubocop-ast (>= 1.31.1, < 2.0)
139
- rubocop-rspec (3.0.1)
140
- rubocop (~> 1.61)
42
+ unicode-display_width (>= 2.4.0, < 4.0)
43
+ rubocop-ast (1.45.1)
44
+ parser (>= 3.3.7.2)
45
+ prism (~> 1.4)
46
+ rubocop-minitest (0.38.1)
47
+ lint_roller (~> 1.1)
48
+ rubocop (>= 1.75.0, < 2.0)
49
+ rubocop-ast (>= 1.38.0, < 2.0)
50
+ rubocop-performance (1.25.0)
51
+ lint_roller (~> 1.1)
52
+ rubocop (>= 1.75.0, < 2.0)
53
+ rubocop-ast (>= 1.38.0, < 2.0)
54
+ rubocop-rake (0.7.1)
55
+ lint_roller (~> 1.1)
56
+ rubocop (>= 1.72.1)
141
57
  ruby-progressbar (1.13.0)
142
58
  simplecov (0.22.0)
143
59
  docile (~> 1.1)
@@ -146,35 +62,33 @@ GEM
146
62
  simplecov-cobertura (2.1.0)
147
63
  rexml
148
64
  simplecov (~> 0.19)
149
- simplecov-html (0.12.3)
65
+ simplecov-html (0.13.1)
150
66
  simplecov_json_formatter (0.1.4)
151
- stringio (3.1.1)
152
- strscan (3.1.0)
153
- thor (1.3.1)
154
- tzinfo (2.0.6)
155
- concurrent-ruby (~> 1.0)
156
- unicode-display_width (2.5.0)
157
- webrick (1.8.1)
158
- yard (0.9.36)
159
- zeitwerk (2.6.16)
67
+ unicode-display_width (3.1.4)
68
+ unicode-emoji (~> 4.0, >= 4.0.4)
69
+ unicode-emoji (4.0.4)
70
+ yard (0.9.37)
160
71
 
161
72
  PLATFORMS
162
73
  arm64-darwin-22
74
+ arm64-darwin-23
75
+ arm64-darwin-24
163
76
  x64-mingw-ucrt
164
77
  x86_64-darwin-20
165
78
  x86_64-linux
166
79
 
167
80
  DEPENDENCIES
168
81
  decoor!
169
- minitest (= 5.24.0)
170
- rake (= 13.2.1)
171
- rspec-rails (= 6.1.3)
172
- rubocop (= 1.64.1)
173
- rubocop-performance (= 1.21.1)
174
- rubocop-rspec (= 3.0.1)
175
- simplecov (= 0.22.0)
176
- simplecov-cobertura (= 2.1.0)
177
- yard (= 0.9.36)
82
+ minitest (~> 5.24)
83
+ minitest-reporters (~> 1.7)
84
+ rake (~> 13.2)
85
+ rubocop (~> 1.65)
86
+ rubocop-minitest (~> 0.38)
87
+ rubocop-performance (~> 1.0)
88
+ rubocop-rake (~> 0.7)
89
+ simplecov (~> 0.22)
90
+ simplecov-cobertura (~> 2.1)
91
+ yard (~> 0.9)
178
92
 
179
93
  BUNDLED WITH
180
- 2.4.22
94
+ 2.5.16
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2024 Yegor Bugayenko
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2024-2025 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # True Object-Oriented Decorator
2
2
 
3
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/decoor)](http://www.rultor.com/p/yegor256/decoor)
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/decoor)](https://www.rultor.com/p/yegor256/decoor)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
6
  [![rake](https://github.com/yegor256/decoor/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/decoor/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/decoor)](http://www.0pdd.com/p?name=yegor256/decoor)
8
- [![Gem Version](https://badge.fury.io/rb/decoor.svg)](http://badge.fury.io/rb/decoor)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/decoor)](https://www.0pdd.com/p?name=yegor256/decoor)
8
+ [![Gem Version](https://badge.fury.io/rb/decoor.svg)](https://badge.fury.io/rb/decoor)
9
9
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/decoor.svg)](https://codecov.io/github/yegor256/decoor?branch=master)
10
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/decoor/master/frames)
10
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/decoor/master/frames)
11
11
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/decoor)](https://hitsofcode.com/view/github/yegor256/decoor)
12
12
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/decoor/blob/master/LICENSE.txt)
13
13
 
@@ -39,7 +39,7 @@ class MyString
39
39
  @origin.strip.split(@br)
40
40
  end
41
41
  end
42
- d = MyString.new('Jeff Lebowski')
42
+ d = MyString.new('Jeff Lebowski', ' ')
43
43
  assert(d.parts == ['Jeff', 'Lebowski'])
44
44
  ```
45
45
 
@@ -49,7 +49,7 @@ That's it.
49
49
 
50
50
  Read
51
51
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
52
- Make sure you build is green before you contribute
52
+ Make sure your build is green before you contribute
53
53
  your pull request. You will need to have
54
54
  [Ruby](https://www.ruby-lang.org/en/) 3.2+ and
55
55
  [Bundler](https://bundler.io/) installed. Then:
data/REUSE.toml ADDED
@@ -0,0 +1,34 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.txt",
14
+ "**/.DS_Store",
15
+ "**/.gitignore",
16
+ "**/.pdd",
17
+ "**/*.csv",
18
+ "**/*.jpg",
19
+ "**/*.json",
20
+ "**/*.md",
21
+ "**/*.pdf",
22
+ "**/*.png",
23
+ "**/*.svg",
24
+ "**/*.txt",
25
+ "**/*.vm",
26
+ "**/CNAME",
27
+ "**/Gemfile.lock",
28
+ "Gemfile.lock",
29
+ "README.md",
30
+ "renovate.json",
31
+ ]
32
+ precedence = "override"
33
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
34
+ SPDX-License-Identifier = "MIT"
data/Rakefile CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'rubygems'
24
7
  require 'rake'
@@ -32,7 +15,7 @@ def version
32
15
  Gem::Specification.load(Dir['*.gemspec'].first).version
33
16
  end
34
17
 
35
- task default: %i[clean test rubocop yard copyright]
18
+ task default: %i[clean test rubocop yard]
36
19
 
37
20
  require 'rake/testtask'
38
21
  desc 'Run all unit tests'
@@ -54,13 +37,4 @@ require 'rubocop/rake_task'
54
37
  desc 'Run RuboCop on all directories'
55
38
  RuboCop::RakeTask.new(:rubocop) do |task|
56
39
  task.fail_on_error = true
57
- task.requires << 'rubocop-rspec'
58
- end
59
-
60
- task :copyright do
61
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
62
- --include '*.rb' \
63
- --include '*.txt' \
64
- --include 'Rakefile' \
65
- ."
66
40
  end
data/decoor.gemspec CHANGED
@@ -1,33 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'English'
24
- require_relative 'lib/decoor'
25
7
 
26
8
  Gem::Specification.new do |s|
27
9
  s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
28
10
  s.required_ruby_version = '>=3.0'
29
11
  s.name = 'decoor'
30
- s.version = '0.0.1'
12
+ s.version = '0.1.0'
31
13
  s.license = 'MIT'
32
14
  s.summary = 'Decoor'
33
15
  s.description =
@@ -37,7 +19,7 @@ Gem::Specification.new do |s|
37
19
  object-oriented.'
38
20
  s.authors = ['Yegor Bugayenko']
39
21
  s.email = 'yegor256@gmail.com'
40
- s.homepage = 'http://github.com/yegor256/decoor.rb'
22
+ s.homepage = 'https://github.com/yegor256/decoor.rb'
41
23
  s.files = `git ls-files`.split($RS)
42
24
  s.rdoc_options = ['--charset=UTF-8']
43
25
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
data/lib/decoor.rb CHANGED
@@ -1,76 +1,93 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
- # A function that turns decorates an object.
24
- #
25
- # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
- # Copyright:: Copyright (c) 2024 Yegor Bugayenko
27
- # License:: MIT
28
- def decoor(origin, attrs = {}, &)
29
- if block_given?
30
- c = Class.new do
31
- def initialize(origin, attrs)
32
- @origin = origin
33
- # rubocop:disable Style/HashEachMethods
34
- # rubocop:disable Lint/UnusedBlockArgument
35
- attrs.each do |k, v|
36
- instance_eval("@#{k} = v", __FILE__, __LINE__) # @foo = v
6
+ # System module, for global functions.
7
+ module Kernel
8
+ # Decorates an object by creating a proxy that delegates method calls to the original object.
9
+ #
10
+ # This function creates a decorator pattern implementation that allows transparent delegation
11
+ # to an origin object while optionally adding additional behavior through a block.
12
+ #
13
+ # When called with a block, it creates a new anonymous class that wraps the origin object
14
+ # and evaluates the block in the context of that class, allowing additional methods to be defined.
15
+ #
16
+ # When called without a block from within a class definition, it sets up method_missing
17
+ # to delegate calls to the specified instance variable.
18
+ #
19
+ # @param origin [Object, Symbol] The object to be decorated (when block given) or the name
20
+ # of an instance variable to delegate to (when no block given)
21
+ # @param attrs [Hash] Optional attributes to be set as instance variables on the decorator
22
+ # (only used when block is given)
23
+ # @yield Block to be evaluated in the context of the decorator class, allowing additional
24
+ # methods to be defined
25
+ # @return [Object] The decorated object (when block given) or nil (when no block given)
26
+ #
27
+ # @example Decorating an object with additional behavior
28
+ # decorated = decoor(original_object, {cache: {}}) do
29
+ # def cached_result
30
+ # @cache[:result] ||= @origin.expensive_operation
31
+ # end
32
+ # end
33
+ #
34
+ # @example Setting up delegation within a class
35
+ # class MyClass
36
+ # def initialize(collaborator)
37
+ # @collaborator = collaborator
38
+ # end
39
+ # decoor :collaborator
40
+ # end
41
+ #
42
+ # @author Yegor Bugayenko (yegor256@gmail.com)
43
+ # @since 0.1.0
44
+ def decoor(origin, attrs = {}, &)
45
+ if block_given?
46
+ c = Class.new do
47
+ def initialize(origin, attrs)
48
+ @origin = origin
49
+ # rubocop:disable Style/HashEachMethods
50
+ # rubocop:disable Lint/UnusedBlockArgument
51
+ attrs.each do |k, v|
52
+ instance_eval("@#{k} = v", __FILE__, __LINE__) # @foo = v
53
+ end
54
+ # rubocop:enable Style/HashEachMethods
55
+ # rubocop:enable Lint/UnusedBlockArgument
37
56
  end
38
- # rubocop:enable Style/HashEachMethods
39
- # rubocop:enable Lint/UnusedBlockArgument
40
- end
41
57
 
42
- def method_missing(*args)
43
- @origin.__send__(*args) do |*a|
44
- yield(*a) if block_given?
58
+ def method_missing(*args)
59
+ @origin.__send__(*args) do |*a|
60
+ yield(*a) if block_given?
61
+ end
45
62
  end
46
- end
47
63
 
48
- def respond_to?(_mtd, _inc = false)
49
- true
50
- end
64
+ def respond_to?(_mtd, _inc = false)
65
+ true
66
+ end
51
67
 
52
- def respond_to_missing?(_mtd, _inc = false)
53
- true
54
- end
55
- end
56
- c.class_eval(&)
57
- c.new(origin, attrs)
58
- else
59
- class_eval("def __get_origin__; @#{origin}; end", __FILE__, __LINE__) # def _get; @name; end
60
- class_eval do
61
- def method_missing(*args)
62
- o = __get_origin__
63
- o.send(*args) do |*a|
64
- yield(*a) if block_given?
68
+ def respond_to_missing?(_mtd, _inc = false)
69
+ true
65
70
  end
66
71
  end
72
+ c.class_eval(&)
73
+ c.new(origin, attrs)
74
+ else
75
+ class_eval("def __get_origin__; @#{origin}; end", __FILE__, __LINE__) # def _get; @name; end
76
+ class_eval do
77
+ def method_missing(*args)
78
+ o = __get_origin__
79
+ o.send(*args) do |*a|
80
+ yield(*a) if block_given?
81
+ end
82
+ end
67
83
 
68
- def respond_to?(_mtd, _inc = false)
69
- true
70
- end
84
+ def respond_to?(_mtd, _inc = false)
85
+ true
86
+ end
71
87
 
72
- def respond_to_missing?(_mtd, _inc = false)
73
- true
88
+ def respond_to_missing?(_mtd, _inc = false)
89
+ true
90
+ end
74
91
  end
75
92
  end
76
93
  end
data/test/test__helper.rb CHANGED
@@ -1,31 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2024 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2024-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  $stdout.sync = true
24
7
 
25
8
  require 'simplecov'
26
- SimpleCov.start
27
-
28
9
  require 'simplecov-cobertura'
29
- SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
10
+ unless SimpleCov.running
11
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(
12
+ [
13
+ SimpleCov::Formatter::HTMLFormatter,
14
+ SimpleCov::Formatter::CoberturaFormatter
15
+ ]
16
+ )
17
+ SimpleCov.minimum_coverage 85
18
+ SimpleCov.minimum_coverage_by_file 85
19
+ SimpleCov.start do
20
+ add_filter 'test/'
21
+ add_filter 'vendor/'
22
+ add_filter 'target/'
23
+ track_files 'lib/**/*.rb'
24
+ end
25
+ end
30
26
 
31
27
  require 'minitest/autorun'
28
+ require 'minitest/reporters'
29
+ Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new]