delegate 0.6.1 → 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: a8537e6d97d8707e29a37239baccb6be764d37aadc748d7bc525ca6f426e3bdc
4
- data.tar.gz: 0cb5bcee38006db2d540ed5ea84fa8f9e08e71abbfc6875f2931153fa6c89a23
3
+ metadata.gz: 2d02460e71183326465e98626c5be2bec0c71f3b9dead6a1355b849c885e23b8
4
+ data.tar.gz: 1745c691350c2555270eac9eaa7b5846be73c01ba906a72989fb972156c671ec
5
5
  SHA512:
6
- metadata.gz: 3ba0a2a005054b94f0789a242300e6e5f63cf5133a58bdd751ab6edcce84b129cf12a181b7e782577dd1eb44b633edde25ffc8dd2ea25aa547f27e4f3f9a8d80
7
- data.tar.gz: f0e941c1b05ff024b2dbc2d864bcda01f1c12db5d8304bfda2aba988f42b875d76fc92541415911dd9b917587fdc01b16beac340426ea8e2999cb46077f7efc0
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.1"
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,13 +346,6 @@ class SimpleDelegator < Delegator
344
346
  end
345
347
  end
346
348
 
347
- def Delegator.delegating_block(mid) # :nodoc:
348
- lambda do |*args, &block|
349
- target = self.__getobj__
350
- target.__send__(mid, *args, &block)
351
- end.ruby2_keywords
352
- end
353
-
354
349
  #
355
350
  # The primary interface to this library. Use to setup delegation when defining
356
351
  # your class.
@@ -400,14 +395,29 @@ def DelegateClass(superclass, &block)
400
395
  public_instance_methods = superclass.public_instance_methods
401
396
  public_instance_methods -= ignores
402
397
 
403
- 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] }
404
401
 
405
- source = normal.map do |method|
406
- "def #{method}(...); __getobj__.#{method}(...); end"
407
- 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
408
408
 
409
- protected_instance_methods.each do |method|
410
- 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
411
421
  end
412
422
 
413
423
  klass.module_eval do
@@ -426,10 +436,6 @@ def DelegateClass(superclass, &block)
426
436
 
427
437
  class_eval(source.join(";"), __FILE__, __LINE__)
428
438
 
429
- special.each do |method|
430
- define_method(method, Delegator.delegating_block(method))
431
- end
432
-
433
439
  protected(*protected_instance_methods)
434
440
  end
435
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.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto