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 +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 -18
- 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,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
|
-
|
|
398
|
+
methods_to_define =
|
|
399
|
+
public_instance_methods.map { |x| [x, false] } +
|
|
400
|
+
protected_instance_methods.map { |x| [x, true] }
|
|
404
401
|
|
|
405
|
-
source =
|
|
406
|
-
|
|
407
|
-
|
|
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
|
-
|
|
410
|
-
|
|
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
|
|