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 +4 -4
- data/.github/workflows/push_gem.yml +3 -3
- data/.github/workflows/sync-ruby.yml +2 -2
- data/.github/workflows/test.yml +1 -1
- data/lib/delegate.rb +24 -22
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d02460e71183326465e98626c5be2bec0c71f3b9dead6a1355b849c885e23b8
|
|
4
|
+
data.tar.gz: 1745c691350c2555270eac9eaa7b5846be73c01ba906a72989fb972156c671ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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@
|
|
26
|
+
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
|
27
27
|
with:
|
|
28
28
|
egress-policy: audit
|
|
29
29
|
|
|
30
|
-
- uses: actions/checkout@
|
|
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@
|
|
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@
|
|
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@
|
|
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 }}
|
data/.github/workflows/test.yml
CHANGED
data/lib/delegate.rb
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
#
|
|
41
41
|
class Delegator < BasicObject
|
|
42
42
|
# The version string
|
|
43
|
-
VERSION = "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
|
-
|
|
398
|
+
methods_to_define =
|
|
399
|
+
public_instance_methods.map { |x| [x, false] } +
|
|
400
|
+
protected_instance_methods.map { |x| [x, true] }
|
|
408
401
|
|
|
409
|
-
source =
|
|
410
|
-
|
|
411
|
-
|
|
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
|
-
|
|
414
|
-
|
|
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
|
|