delegate 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +24 -0
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/Rakefile +7 -0
- data/delegate.gemspec +15 -9
- data/lib/delegate.rb +49 -34
- metadata +11 -11
- 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: dc397384e2431f310f68623dc90452d5d30422a6420cd2375a989c0ab76f2c3d
|
4
|
+
data.tar.gz: b6b2e957f8b6edc91dc328c19f8d94f10021bc902adc839baf7412c831faa386
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 957fccf5fbbc8648671b38c1bf487c7b1ce7fcad2b8f7d634e5e30959698bc93259d637cb468ece1d630661c2adc2bc7b5d228cea5a31dab30e4fdf10e011511
|
7
|
+
data.tar.gz: fc3a860ae2ffdb5873d810d80420f46565fd1692f0e573879318ca13c597e6aa4b0c090c172d60c24b11515a608fcda1684639c50af0cc47ada125f6f866a0e0
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: test
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: build (${{ matrix.ruby }} / ${{ matrix.os }})
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby: [ head ]
|
11
|
+
os: [ ubuntu-latest, macos-latest ]
|
12
|
+
runs-on: ${{ matrix.os }}
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@master
|
15
|
+
- name: Set up Ruby
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby }}
|
19
|
+
- name: Install dependencies
|
20
|
+
run: |
|
21
|
+
gem install bundler --no-document
|
22
|
+
bundle install
|
23
|
+
- name: Run test
|
24
|
+
run: 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/test/unit/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,31 @@
|
|
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
27
|
spec.bindir = "exe"
|
23
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
29
|
spec.require_paths = ["lib"]
|
30
|
+
spec.required_ruby_version = '>= 2.7'
|
25
31
|
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,6 +39,8 @@
|
|
37
39
|
# Be advised, RDoc will not detect delegated methods.
|
38
40
|
#
|
39
41
|
class Delegator < BasicObject
|
42
|
+
VERSION = "0.2.0"
|
43
|
+
|
40
44
|
kernel = ::Kernel.dup
|
41
45
|
kernel.class_eval do
|
42
46
|
alias __raise__ raise
|
@@ -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,24 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: delegate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- Yukihiro Matsumoto
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-22 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/workflows/test.yml"
|
20
21
|
- ".gitignore"
|
21
|
-
- ".travis.yml"
|
22
22
|
- Gemfile
|
23
23
|
- LICENSE.txt
|
24
24
|
- README.md
|
@@ -27,14 +27,14 @@ files:
|
|
27
27
|
- bin/setup
|
28
28
|
- delegate.gemspec
|
29
29
|
- lib/delegate.rb
|
30
|
-
- lib/delegate/version.rb
|
31
30
|
homepage: https://github.com/ruby/delegate
|
32
31
|
licenses:
|
32
|
+
- Ruby
|
33
33
|
- BSD-2-Clause
|
34
34
|
metadata:
|
35
35
|
homepage_uri: https://github.com/ruby/delegate
|
36
36
|
source_code_uri: https://github.com/ruby/delegate
|
37
|
-
post_install_message:
|
37
|
+
post_install_message:
|
38
38
|
rdoc_options: []
|
39
39
|
require_paths:
|
40
40
|
- lib
|
@@ -42,15 +42,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
42
42
|
requirements:
|
43
43
|
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
45
|
+
version: '2.7'
|
46
46
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
47
|
requirements:
|
48
48
|
- - ">="
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
|
-
rubygems_version: 3.
|
53
|
-
signing_key:
|
52
|
+
rubygems_version: 3.2.2
|
53
|
+
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Provides three abilities to delegate method calls to an object.
|
56
56
|
test_files: []
|
data/.travis.yml
DELETED
data/lib/delegate/version.rb
DELETED