delegate 0.6.0 → 0.7.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: 9fd09bc1c57e6112ca448780e877b5a07681c642937cf2457895be0dd05f990a
4
- data.tar.gz: c9d806a0105bdd3a7ea904d8c829687bec4bf57fba9056ee8397186b4f05f108
3
+ metadata.gz: 2d02460e71183326465e98626c5be2bec0c71f3b9dead6a1355b849c885e23b8
4
+ data.tar.gz: 1745c691350c2555270eac9eaa7b5846be73c01ba906a72989fb972156c671ec
5
5
  SHA512:
6
- metadata.gz: aff48e6ba7051a1d421248d0a67cd760d3c680d5df7cb5778636d5d843a4afc3a96b10469872acfa51a702eb21c9f65df41cd205878975089dfecb0aa7c42853
7
- data.tar.gz: 3482081f54f59d708691a45065f80f676d77571fc986f5f92c823c24fea6281f9b373f2a00095522fe0afc57803084864a647e06546791996affbdcb1c2f17d0
6
+ metadata.gz: 2e5d5301e00017f3fc7d330c9eb50a7ac1723e2a0df9a18b46281c2170b8ccb384fac9c21273e8ae183a84a2638408d67a613a5175eae89380168938c86d580b
7
+ data.tar.gz: ac6bb3db8b1007c1ec136c66234aef9b12bc5401a9ea0deccc72ae24caccfc2f00503889058b5d91d08ad48a4797012d6452fdc923e35dd15dc66964e3109920
@@ -23,11 +23,11 @@ jobs:
23
23
 
24
24
  steps:
25
25
  - name: Harden Runner
26
- uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
26
+ uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
27
27
  with:
28
28
  egress-policy: audit
29
29
 
30
- - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
30
+ - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
31
31
 
32
32
  - name: Set up Ruby
33
33
  uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0
@@ -36,7 +36,7 @@ jobs:
36
36
  ruby-version: ruby
37
37
 
38
38
  - name: Publish to RubyGems
39
- uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2
39
+ uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1
40
40
 
41
41
  - name: Create GitHub release
42
42
  run: |
@@ -8,11 +8,11 @@ jobs:
8
8
  runs-on: ubuntu-latest
9
9
  if: ${{ github.repository_owner == 'ruby' }}
10
10
  steps:
11
- - uses: actions/checkout@v6
11
+ - uses: actions/checkout@v7
12
12
 
13
13
  - name: Create GitHub App token
14
14
  id: app-token
15
- uses: actions/create-github-app-token@v2
15
+ uses: actions/create-github-app-token@v3
16
16
  with:
17
17
  app-id: 2060836
18
18
  private-key: ${{ secrets.RUBY_SYNC_DEFAULT_GEMS_PRIVATE_KEY }}
@@ -17,7 +17,7 @@ jobs:
17
17
  os: [ ubuntu-latest, macos-latest ]
18
18
  runs-on: ${{ matrix.os }}
19
19
  steps:
20
- - uses: actions/checkout@v6
20
+ - uses: actions/checkout@v7
21
21
  - name: Set up Ruby
22
22
  uses: ruby/setup-ruby@v1
23
23
  with:
data/lib/delegate.rb CHANGED
@@ -40,7 +40,7 @@
40
40
  #
41
41
  class Delegator < BasicObject
42
42
  # The version string
43
- VERSION = "0.6.0"
43
+ VERSION = "0.7.0"
44
44
 
45
45
  kernel = ::Kernel.dup
46
46
  kernel.class_eval do
@@ -252,6 +252,8 @@ end
252
252
  # and even to change the object being delegated to at a later time with
253
253
  # #__setobj__.
254
254
  #
255
+ # require 'date'
256
+ #
255
257
  # class User
256
258
  # def born_on
257
259
  # Date.new(1989, 9, 10)
@@ -344,17 +346,6 @@ class SimpleDelegator < Delegator
344
346
  end
345
347
  end
346
348
 
347
- def Delegator.delegating_code(mid) # :nodoc:
348
- line = __LINE__+2
349
- src = <<~RUBY
350
- ruby2_keywords def #{mid}(*args, &block)
351
- target = self.__getobj__
352
- target.__send__(:'#{mid}', *args, &block)
353
- end
354
- RUBY
355
- [src, __FILE__, line]
356
- end
357
-
358
349
  #
359
350
  # The primary interface to this library. Use to setup delegation when defining
360
351
  # your class.
@@ -404,14 +395,29 @@ def DelegateClass(superclass, &block)
404
395
  public_instance_methods = superclass.public_instance_methods
405
396
  public_instance_methods -= ignores
406
397
 
407
- normal, special = public_instance_methods.partition { |m| m.match?(/\A[a-zA-Z]\w*[!\?]?\z/) }
398
+ methods_to_define =
399
+ public_instance_methods.map { |x| [x, false] } +
400
+ protected_instance_methods.map { |x| [x, true] }
408
401
 
409
- source = normal.map do |method|
410
- "def #{method}(...); __getobj__.#{method}(...); end"
411
- end
402
+ source = []
403
+
404
+ methods_to_define.each do |target_name, is_protected|
405
+ unless target_name.match?(/\A[_a-zA-Z]\w*[!\?]?\z/)
406
+ placeholder_name = :__delegate
407
+ end
412
408
 
413
- protected_instance_methods.each do |method|
414
- source << "def #{method}(...); __getobj__.__send__(#{method.inspect}, ...); end"
409
+ send_source =
410
+ if is_protected || placeholder_name
411
+ "__getobj__.__send__(#{target_name.inspect}, ...)"
412
+ else
413
+ "__getobj__.#{target_name}(...)"
414
+ end
415
+ source << "def #{placeholder_name || target_name}(...); #{send_source}; end"
416
+
417
+ if placeholder_name
418
+ source << "alias_method #{target_name.inspect}, :#{placeholder_name}"
419
+ source << "remove_method :#{placeholder_name}"
420
+ end
415
421
  end
416
422
 
417
423
  klass.module_eval do
@@ -430,10 +436,6 @@ def DelegateClass(superclass, &block)
430
436
 
431
437
  class_eval(source.join(";"), __FILE__, __LINE__)
432
438
 
433
- special.each do |method|
434
- module_eval(*Delegator.delegating_code(method))
435
- end
436
-
437
439
  protected(*protected_instance_methods)
438
440
  end
439
441
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delegate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto