delegate 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/test.yml +31 -0
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/Rakefile +7 -0
- data/delegate.gemspec +15 -11
- data/lib/delegate.rb +50 -35
- metadata +13 -12
- data/.travis.yml +0 -7
- data/lib/delegate/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e866777bc83135233d96ebe09f3d7e4206e6d477afab28095ecf8481c3efde1
|
4
|
+
data.tar.gz: 3964f37ef7c61538dcc895c5d0cd1b17db828ccda4c46628727852b2462c7b3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff7d08ab37f382addb6737c90c3a636694c7ed578ad843615465319c2fdd6d247562a7ee37c46a6124dedd193df61d417928630b925e3279e0d4d5bf2e90c66e
|
7
|
+
data.tar.gz: 888dc049d92b1dde0fa900e024e1e0921a43be6dbab3685cfbf59abf450ab3d63ed43cec1fffb56b2272d466d2d5fe8dbba13c46044c7082792ce62a188671dd
|
@@ -0,0 +1,31 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
ruby-versions:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
outputs:
|
9
|
+
versions: ${{ steps.versions.outputs.value }}
|
10
|
+
steps:
|
11
|
+
- id: versions
|
12
|
+
run: |
|
13
|
+
versions=$(curl -s 'https://cache.ruby-lang.org/pub/misc/ci_versions/cruby.json' | jq -c '. - ["2.7"]')
|
14
|
+
echo "::set-output name=value::${versions}"
|
15
|
+
test:
|
16
|
+
needs: ruby-versions
|
17
|
+
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
18
|
+
strategy:
|
19
|
+
matrix:
|
20
|
+
ruby: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
21
|
+
os: [ ubuntu-latest, macos-latest ]
|
22
|
+
runs-on: ${{ matrix.os }}
|
23
|
+
steps:
|
24
|
+
- uses: actions/checkout@v3
|
25
|
+
- name: Set up Ruby
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby }}
|
29
|
+
bundler-cache: true # 'bundle install' and cache gems
|
30
|
+
- name: Run test
|
31
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -56,4 +56,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
56
56
|
|
57
57
|
## Contributing
|
58
58
|
|
59
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
59
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/delegate.
|
data/Rakefile
CHANGED
@@ -7,4 +7,11 @@ Rake::TestTask.new(:test) do |t|
|
|
7
7
|
t.test_files = FileList["test/**/test_*.rb"]
|
8
8
|
end
|
9
9
|
|
10
|
+
task :sync_tool do
|
11
|
+
require 'fileutils'
|
12
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
|
+
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
|
+
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
|
+
end
|
16
|
+
|
10
17
|
task :default => :test
|
data/delegate.gemspec
CHANGED
@@ -1,25 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
name = File.basename(__FILE__, ".gemspec")
|
4
|
+
version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
|
5
|
+
break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
|
6
|
+
/^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
|
7
|
+
end rescue nil
|
8
|
+
end
|
4
9
|
|
5
10
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
7
|
-
spec.version =
|
8
|
-
spec.authors = ["
|
9
|
-
spec.email = ["
|
11
|
+
spec.name = name
|
12
|
+
spec.version = version
|
13
|
+
spec.authors = ["Yukihiro Matsumoto"]
|
14
|
+
spec.email = ["matz@ruby-lang.org"]
|
10
15
|
|
11
16
|
spec.summary = %q{Provides three abilities to delegate method calls to an object.}
|
12
17
|
spec.description = %q{Provides three abilities to delegate method calls to an object.}
|
13
18
|
spec.homepage = "https://github.com/ruby/delegate"
|
14
|
-
spec.
|
19
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
15
20
|
|
16
21
|
spec.metadata["homepage_uri"] = spec.homepage
|
17
22
|
spec.metadata["source_code_uri"] = spec.homepage
|
18
23
|
|
19
24
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
26
|
end
|
22
|
-
spec.bindir = "exe"
|
23
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
27
|
spec.require_paths = ["lib"]
|
28
|
+
spec.required_ruby_version = '>= 2.7'
|
25
29
|
end
|
data/lib/delegate.rb
CHANGED
@@ -21,6 +21,8 @@
|
|
21
21
|
# SimpleDelegator's implementation serves as a nice example of the use of
|
22
22
|
# Delegator:
|
23
23
|
#
|
24
|
+
# require 'delegate'
|
25
|
+
#
|
24
26
|
# class SimpleDelegator < Delegator
|
25
27
|
# def __getobj__
|
26
28
|
# @delegate_sd_obj # return object we are delegating to, required
|
@@ -37,10 +39,12 @@
|
|
37
39
|
# Be advised, RDoc will not detect delegated methods.
|
38
40
|
#
|
39
41
|
class Delegator < BasicObject
|
42
|
+
VERSION = "0.3.0"
|
43
|
+
|
40
44
|
kernel = ::Kernel.dup
|
41
45
|
kernel.class_eval do
|
42
46
|
alias __raise__ raise
|
43
|
-
[:to_s, :inspect,
|
47
|
+
[:to_s, :inspect, :!~, :===, :<=>, :hash].each do |m|
|
44
48
|
undef_method m
|
45
49
|
end
|
46
50
|
private_instance_methods.each do |m|
|
@@ -75,14 +79,14 @@ class Delegator < BasicObject
|
|
75
79
|
#
|
76
80
|
# Handles the magic of delegation through \_\_getobj\_\_.
|
77
81
|
#
|
78
|
-
def method_missing(m, *args, &block)
|
82
|
+
ruby2_keywords def method_missing(m, *args, &block)
|
79
83
|
r = true
|
80
84
|
target = self.__getobj__ {r = false}
|
81
85
|
|
82
|
-
if r &&
|
86
|
+
if r && target_respond_to?(target, m, false)
|
83
87
|
target.__send__(m, *args, &block)
|
84
88
|
elsif ::Kernel.method_defined?(m) || ::Kernel.private_method_defined?(m)
|
85
|
-
::Kernel.instance_method(m).
|
89
|
+
::Kernel.instance_method(m).bind_call(self, *args, &block)
|
86
90
|
else
|
87
91
|
super(m, *args, &block)
|
88
92
|
end
|
@@ -95,14 +99,31 @@ class Delegator < BasicObject
|
|
95
99
|
def respond_to_missing?(m, include_private)
|
96
100
|
r = true
|
97
101
|
target = self.__getobj__ {r = false}
|
98
|
-
r &&=
|
99
|
-
if r && include_private && !
|
102
|
+
r &&= target_respond_to?(target, m, include_private)
|
103
|
+
if r && include_private && !target_respond_to?(target, m, false)
|
100
104
|
warn "delegator does not forward private method \##{m}", uplevel: 3
|
101
105
|
return false
|
102
106
|
end
|
103
107
|
r
|
104
108
|
end
|
105
109
|
|
110
|
+
KERNEL_RESPOND_TO = ::Kernel.instance_method(:respond_to?)
|
111
|
+
private_constant :KERNEL_RESPOND_TO
|
112
|
+
|
113
|
+
# Handle BasicObject instances
|
114
|
+
private def target_respond_to?(target, m, include_private)
|
115
|
+
case target
|
116
|
+
when Object
|
117
|
+
target.respond_to?(m, include_private)
|
118
|
+
else
|
119
|
+
if KERNEL_RESPOND_TO.bind_call(target, :respond_to?)
|
120
|
+
target.respond_to?(m, include_private)
|
121
|
+
else
|
122
|
+
KERNEL_RESPOND_TO.bind_call(target, m, include_private)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
106
127
|
#
|
107
128
|
# Returns the methods available to this delegate object as the union
|
108
129
|
# of this object's and \_\_getobj\_\_ methods.
|
@@ -201,44 +222,21 @@ class Delegator < BasicObject
|
|
201
222
|
end
|
202
223
|
end
|
203
224
|
|
204
|
-
def initialize_clone(obj) # :nodoc:
|
205
|
-
self.__setobj__(obj.__getobj__.clone)
|
225
|
+
def initialize_clone(obj, freeze: nil) # :nodoc:
|
226
|
+
self.__setobj__(obj.__getobj__.clone(freeze: freeze))
|
206
227
|
end
|
207
228
|
def initialize_dup(obj) # :nodoc:
|
208
229
|
self.__setobj__(obj.__getobj__.dup)
|
209
230
|
end
|
210
231
|
private :initialize_clone, :initialize_dup
|
211
232
|
|
212
|
-
##
|
213
|
-
# :method: trust
|
214
|
-
# Trust both the object returned by \_\_getobj\_\_ and self.
|
215
|
-
#
|
216
|
-
|
217
|
-
##
|
218
|
-
# :method: untrust
|
219
|
-
# Untrust both the object returned by \_\_getobj\_\_ and self.
|
220
|
-
#
|
221
|
-
|
222
|
-
##
|
223
|
-
# :method: taint
|
224
|
-
# Taint both the object returned by \_\_getobj\_\_ and self.
|
225
|
-
#
|
226
|
-
|
227
|
-
##
|
228
|
-
# :method: untaint
|
229
|
-
# Untaint both the object returned by \_\_getobj\_\_ and self.
|
230
|
-
#
|
231
|
-
|
232
233
|
##
|
233
234
|
# :method: freeze
|
234
235
|
# Freeze both the object returned by \_\_getobj\_\_ and self.
|
235
236
|
#
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
__getobj__.send(method)
|
240
|
-
super()
|
241
|
-
end
|
237
|
+
def freeze
|
238
|
+
__getobj__.freeze
|
239
|
+
super()
|
242
240
|
end
|
243
241
|
|
244
242
|
@delegator_api = self.public_instance_methods
|
@@ -259,6 +257,8 @@ end
|
|
259
257
|
# end
|
260
258
|
# end
|
261
259
|
#
|
260
|
+
# require 'delegate'
|
261
|
+
#
|
262
262
|
# class UserDecorator < SimpleDelegator
|
263
263
|
# def birth_year
|
264
264
|
# born_on.year
|
@@ -347,7 +347,7 @@ def Delegator.delegating_block(mid) # :nodoc:
|
|
347
347
|
lambda do |*args, &block|
|
348
348
|
target = self.__getobj__
|
349
349
|
target.__send__(mid, *args, &block)
|
350
|
-
end
|
350
|
+
end.ruby2_keywords
|
351
351
|
end
|
352
352
|
|
353
353
|
#
|
@@ -424,6 +424,21 @@ def DelegateClass(superclass, &block)
|
|
424
424
|
klass.define_singleton_method :protected_instance_methods do |all=true|
|
425
425
|
super(all) | superclass.protected_instance_methods
|
426
426
|
end
|
427
|
+
klass.define_singleton_method :instance_methods do |all=true|
|
428
|
+
super(all) | superclass.instance_methods
|
429
|
+
end
|
430
|
+
klass.define_singleton_method :public_instance_method do |name|
|
431
|
+
super(name)
|
432
|
+
rescue NameError
|
433
|
+
raise unless self.public_instance_methods.include?(name)
|
434
|
+
superclass.public_instance_method(name)
|
435
|
+
end
|
436
|
+
klass.define_singleton_method :instance_method do |name|
|
437
|
+
super(name)
|
438
|
+
rescue NameError
|
439
|
+
raise unless self.instance_methods.include?(name)
|
440
|
+
superclass.instance_method(name)
|
441
|
+
end
|
427
442
|
klass.module_eval(&block) if block
|
428
443
|
return klass
|
429
444
|
end
|
metadata
CHANGED
@@ -1,24 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delegate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
7
|
+
- Yukihiro Matsumoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Provides three abilities to delegate method calls to an object.
|
14
14
|
email:
|
15
|
-
-
|
15
|
+
- matz@ruby-lang.org
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
+
- ".github/dependabot.yml"
|
21
|
+
- ".github/workflows/test.yml"
|
20
22
|
- ".gitignore"
|
21
|
-
- ".travis.yml"
|
22
23
|
- Gemfile
|
23
24
|
- LICENSE.txt
|
24
25
|
- README.md
|
@@ -27,14 +28,14 @@ files:
|
|
27
28
|
- bin/setup
|
28
29
|
- delegate.gemspec
|
29
30
|
- lib/delegate.rb
|
30
|
-
- lib/delegate/version.rb
|
31
31
|
homepage: https://github.com/ruby/delegate
|
32
32
|
licenses:
|
33
|
+
- Ruby
|
33
34
|
- BSD-2-Clause
|
34
35
|
metadata:
|
35
36
|
homepage_uri: https://github.com/ruby/delegate
|
36
37
|
source_code_uri: https://github.com/ruby/delegate
|
37
|
-
post_install_message:
|
38
|
+
post_install_message:
|
38
39
|
rdoc_options: []
|
39
40
|
require_paths:
|
40
41
|
- lib
|
@@ -42,15 +43,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
43
|
requirements:
|
43
44
|
- - ">="
|
44
45
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
46
|
+
version: '2.7'
|
46
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
48
|
requirements:
|
48
49
|
- - ">="
|
49
50
|
- !ruby/object:Gem::Version
|
50
51
|
version: '0'
|
51
52
|
requirements: []
|
52
|
-
rubygems_version: 3.0.
|
53
|
-
signing_key:
|
53
|
+
rubygems_version: 3.4.0.dev
|
54
|
+
signing_key:
|
54
55
|
specification_version: 4
|
55
56
|
summary: Provides three abilities to delegate method calls to an object.
|
56
57
|
test_files: []
|
data/.travis.yml
DELETED
data/lib/delegate/version.rb
DELETED