delegate 0.4.0 → 0.6.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: 26e783faa009ab88d7d397307819b967c1ee35025e531f634b45bd8ef8b45d08
4
- data.tar.gz: df1a5706de8e3bfd18d05372b91d490e1c50a6908e98fec857bba923cd7cf9d8
3
+ metadata.gz: 9fd09bc1c57e6112ca448780e877b5a07681c642937cf2457895be0dd05f990a
4
+ data.tar.gz: c9d806a0105bdd3a7ea904d8c829687bec4bf57fba9056ee8397186b4f05f108
5
5
  SHA512:
6
- metadata.gz: f0a4a912cf47aa19d62a6827bd1db9cb3022659af13a7902a65a890d801c1be8d7558e0c10c36bcc31f5ca27f5252138d61310d8a203eb5eba00519b74ab042b
7
- data.tar.gz: 248eb7d6cde226b135f984510d1584cb8f1aa94b49b7ce50f59b92401cc54e611c369ba267a4af24104ea88eefd12a42dbf21eb5f93a572b28218d8c45f1f4af
6
+ metadata.gz: aff48e6ba7051a1d421248d0a67cd760d3c680d5df7cb5778636d5d843a4afc3a96b10469872acfa51a702eb21c9f65df41cd205878975089dfecb0aa7c42853
7
+ data.tar.gz: 3482081f54f59d708691a45065f80f676d77571fc986f5f92c823c24fea6281f9b373f2a00095522fe0afc57803084864a647e06546791996affbdcb1c2f17d0
data/.document ADDED
@@ -0,0 +1,4 @@
1
+ BSDL
2
+ COPYING
3
+ README.md
4
+ lib/
@@ -0,0 +1,4 @@
1
+ changelog:
2
+ exclude:
3
+ labels:
4
+ - dependencies # Added by Dependabot
@@ -23,24 +23,24 @@ jobs:
23
23
 
24
24
  steps:
25
25
  - name: Harden Runner
26
- uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
26
+ uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
27
27
  with:
28
28
  egress-policy: audit
29
29
 
30
- - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
30
+ - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
31
31
 
32
32
  - name: Set up Ruby
33
- uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0
33
+ uses: ruby/setup-ruby@d5126b9b3579e429dd52e51e68624dda2e05be25 # v1.267.0
34
34
  with:
35
35
  bundler-cache: true
36
36
  ruby-version: ruby
37
37
 
38
38
  - name: Publish to RubyGems
39
- uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1
39
+ uses: rubygems/release-gem@1c162a739e8b4cb21a676e97b087e8268d8fc40b # v1.1.2
40
40
 
41
41
  - name: Create GitHub release
42
42
  run: |
43
43
  tag_name="$(git describe --tags --abbrev=0)"
44
44
  gh release create "${tag_name}" --verify-tag --generate-notes
45
45
  env:
46
- GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }}
46
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,33 @@
1
+ name: Sync ruby
2
+ on:
3
+ push:
4
+ branches: [master]
5
+ jobs:
6
+ sync:
7
+ name: Sync ruby
8
+ runs-on: ubuntu-latest
9
+ if: ${{ github.repository_owner == 'ruby' }}
10
+ steps:
11
+ - uses: actions/checkout@v6
12
+
13
+ - name: Create GitHub App token
14
+ id: app-token
15
+ uses: actions/create-github-app-token@v2
16
+ with:
17
+ app-id: 2060836
18
+ private-key: ${{ secrets.RUBY_SYNC_DEFAULT_GEMS_PRIVATE_KEY }}
19
+ owner: ruby
20
+ repositories: ruby
21
+
22
+ - name: Sync to ruby/ruby
23
+ uses: convictional/trigger-workflow-and-wait@v1.6.5
24
+ with:
25
+ owner: ruby
26
+ repo: ruby
27
+ workflow_file_name: sync_default_gems.yml
28
+ github_token: ${{ steps.app-token.outputs.token }}
29
+ ref: master
30
+ client_payload: |
31
+ {"gem":"${{ github.event.repository.name }}","before":"${{ github.event.before }}","after":"${{ github.event.after }}"}
32
+ propagate_failure: true
33
+ wait_interval: 10
@@ -17,11 +17,11 @@ jobs:
17
17
  os: [ ubuntu-latest, macos-latest ]
18
18
  runs-on: ${{ matrix.os }}
19
19
  steps:
20
- - uses: actions/checkout@v4
20
+ - uses: actions/checkout@v6
21
21
  - name: Set up Ruby
22
22
  uses: ruby/setup-ruby@v1
23
23
  with:
24
24
  ruby-version: ${{ matrix.ruby }}
25
- - run: bundle install --jobs 4 --retry 3
25
+ bundler-cache: true # 'bundle install' and cache gems
26
26
  - name: Run test
27
27
  run: bundle exec rake test
data/lib/delegate.rb CHANGED
@@ -39,7 +39,8 @@
39
39
  # Be advised, RDoc will not detect delegated methods.
40
40
  #
41
41
  class Delegator < BasicObject
42
- VERSION = "0.4.0"
42
+ # The version string
43
+ VERSION = "0.6.0"
43
44
 
44
45
  kernel = ::Kernel.dup
45
46
  kernel.class_eval do
@@ -77,7 +78,7 @@ class Delegator < BasicObject
77
78
  end
78
79
 
79
80
  #
80
- # Handles the magic of delegation through \_\_getobj\_\_.
81
+ # Handles the magic of delegation through +__getobj__+.
81
82
  #
82
83
  ruby2_keywords def method_missing(m, *args, &block)
83
84
  r = true
@@ -94,7 +95,7 @@ class Delegator < BasicObject
94
95
 
95
96
  #
96
97
  # Checks for a method provided by this the delegate object by forwarding the
97
- # call through \_\_getobj\_\_.
98
+ # call through +__getobj__+.
98
99
  #
99
100
  def respond_to_missing?(m, include_private)
100
101
  r = true
@@ -107,7 +108,7 @@ class Delegator < BasicObject
107
108
  r
108
109
  end
109
110
 
110
- KERNEL_RESPOND_TO = ::Kernel.instance_method(:respond_to?)
111
+ KERNEL_RESPOND_TO = ::Kernel.instance_method(:respond_to?) # :nodoc:
111
112
  private_constant :KERNEL_RESPOND_TO
112
113
 
113
114
  # Handle BasicObject instances
@@ -126,7 +127,7 @@ class Delegator < BasicObject
126
127
 
127
128
  #
128
129
  # Returns the methods available to this delegate object as the union
129
- # of this object's and \_\_getobj\_\_ methods.
130
+ # of this object's and +__getobj__+ methods.
130
131
  #
131
132
  def methods(all=true)
132
133
  __getobj__.methods(all) | super
@@ -134,7 +135,7 @@ class Delegator < BasicObject
134
135
 
135
136
  #
136
137
  # Returns the methods available to this delegate object as the union
137
- # of this object's and \_\_getobj\_\_ public methods.
138
+ # of this object's and +__getobj__+ public methods.
138
139
  #
139
140
  def public_methods(all=true)
140
141
  __getobj__.public_methods(all) | super
@@ -142,7 +143,7 @@ class Delegator < BasicObject
142
143
 
143
144
  #
144
145
  # Returns the methods available to this delegate object as the union
145
- # of this object's and \_\_getobj\_\_ protected methods.
146
+ # of this object's and +__getobj__+ protected methods.
146
147
  #
147
148
  def protected_methods(all=true)
148
149
  __getobj__.protected_methods(all) | super
@@ -175,7 +176,7 @@ class Delegator < BasicObject
175
176
  end
176
177
 
177
178
  #
178
- # Delegates ! to the \_\_getobj\_\_
179
+ # Delegates ! to the +__getobj__+
179
180
  #
180
181
  def !
181
182
  !__getobj__
@@ -198,7 +199,7 @@ class Delegator < BasicObject
198
199
  end
199
200
 
200
201
  #
201
- # Serialization support for the object returned by \_\_getobj\_\_.
202
+ # Serialization support for the object returned by +__getobj__+.
202
203
  #
203
204
  def marshal_dump
204
205
  ivars = instance_variables.reject {|var| /\A@delegate_/ =~ var}
@@ -232,7 +233,7 @@ class Delegator < BasicObject
232
233
 
233
234
  ##
234
235
  # :method: freeze
235
- # Freeze both the object returned by \_\_getobj\_\_ and self.
236
+ # Freeze both the object returned by +__getobj__+ and self.
236
237
  #
237
238
  def freeze
238
239
  __getobj__.freeze
@@ -343,11 +344,15 @@ class SimpleDelegator < Delegator
343
344
  end
344
345
  end
345
346
 
346
- def Delegator.delegating_block(mid) # :nodoc:
347
- lambda do |*args, &block|
347
+ def Delegator.delegating_code(mid) # :nodoc:
348
+ line = __LINE__+2
349
+ src = <<~RUBY
350
+ ruby2_keywords def #{mid}(*args, &block)
348
351
  target = self.__getobj__
349
- target.__send__(mid, *args, &block)
350
- end.ruby2_keywords
352
+ target.__send__(:'#{mid}', *args, &block)
353
+ end
354
+ RUBY
355
+ [src, __FILE__, line]
351
356
  end
352
357
 
353
358
  #
@@ -398,6 +403,17 @@ def DelegateClass(superclass, &block)
398
403
  protected_instance_methods -= ignores
399
404
  public_instance_methods = superclass.public_instance_methods
400
405
  public_instance_methods -= ignores
406
+
407
+ normal, special = public_instance_methods.partition { |m| m.match?(/\A[a-zA-Z]\w*[!\?]?\z/) }
408
+
409
+ source = normal.map do |method|
410
+ "def #{method}(...); __getobj__.#{method}(...); end"
411
+ end
412
+
413
+ protected_instance_methods.each do |method|
414
+ source << "def #{method}(...); __getobj__.__send__(#{method.inspect}, ...); end"
415
+ end
416
+
401
417
  klass.module_eval do
402
418
  def __getobj__ # :nodoc:
403
419
  unless defined?(@delegate_dc_obj)
@@ -406,18 +422,21 @@ def DelegateClass(superclass, &block)
406
422
  end
407
423
  @delegate_dc_obj
408
424
  end
425
+
409
426
  def __setobj__(obj) # :nodoc:
410
427
  __raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
411
428
  @delegate_dc_obj = obj
412
429
  end
413
- protected_instance_methods.each do |method|
414
- define_method(method, Delegator.delegating_block(method))
415
- protected method
416
- end
417
- public_instance_methods.each do |method|
418
- define_method(method, Delegator.delegating_block(method))
430
+
431
+ class_eval(source.join(";"), __FILE__, __LINE__)
432
+
433
+ special.each do |method|
434
+ module_eval(*Delegator.delegating_code(method))
419
435
  end
436
+
437
+ protected(*protected_instance_methods)
420
438
  end
439
+
421
440
  klass.define_singleton_method :public_instance_methods do |all=true|
422
441
  super(all) | superclass.public_instance_methods
423
442
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delegate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-11-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies: []
13
12
  description: Provides three abilities to delegate method calls to an object.
14
13
  email:
@@ -17,8 +16,11 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
19
+ - ".document"
20
20
  - ".github/dependabot.yml"
21
+ - ".github/release.yml"
21
22
  - ".github/workflows/push_gem.yml"
23
+ - ".github/workflows/sync-ruby.yml"
22
24
  - ".github/workflows/test.yml"
23
25
  - ".gitignore"
24
26
  - BSDL
@@ -37,7 +39,6 @@ licenses:
37
39
  metadata:
38
40
  homepage_uri: https://github.com/ruby/delegate
39
41
  source_code_uri: https://github.com/ruby/delegate
40
- post_install_message:
41
42
  rdoc_options: []
42
43
  require_paths:
43
44
  - lib
@@ -52,8 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
55
  requirements: []
55
- rubygems_version: 3.5.11
56
- signing_key:
56
+ rubygems_version: 3.6.9
57
57
  specification_version: 4
58
58
  summary: Provides three abilities to delegate method calls to an object.
59
59
  test_files: []