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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cd16ea3c730a702d06a1721e2213829db7c2ccc0109aa267fa62201f9f5b910
4
- data.tar.gz: 7e46d4c7174ff100079239050e33e41589c9d1a553d8497ab0fb763b22939835
3
+ metadata.gz: 4e866777bc83135233d96ebe09f3d7e4206e6d477afab28095ecf8481c3efde1
4
+ data.tar.gz: 3964f37ef7c61538dcc895c5d0cd1b17db828ccda4c46628727852b2462c7b3f
5
5
  SHA512:
6
- metadata.gz: 9779b0aa3f86278c7ddef289936be20530e6056c22cfca97039740495a80e9cd9f77d22cb51ff6bc02e9b43e7dfdb3917dd22bd0fb93bf6e38c8858d6080e174
7
- data.tar.gz: 7d1ce7b641a66022ac9ef56f46dbcfd0999fdd4f6834fbdfb4142d0fbb39fa689a4007395657704f174181709ca251e5f78965e9cbead70b8a8f9cb0f0d8bc3a
6
+ metadata.gz: ff7d08ab37f382addb6737c90c3a636694c7ed578ad843615465319c2fdd6d247562a7ee37c46a6124dedd193df61d417928630b925e3279e0d4d5bf2e90c66e
7
+ data.tar.gz: 888dc049d92b1dde0fa900e024e1e0921a43be6dbab3685cfbf59abf450ab3d63ed43cec1fffb56b2272d466d2d5fe8dbba13c46044c7082792ce62a188671dd
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: 'github-actions'
4
+ directory: '/'
5
+ schedule:
6
+ interval: 'weekly'
@@ -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
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /Gemfile.lock
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/hsbt/delegate.
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
- lib = File.expand_path("lib", __dir__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "delegate/version"
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 = "delegate"
7
- spec.version = Delegator::VERSION
8
- spec.authors = ["Hiroshi SHIBATA"]
9
- spec.email = ["hsbt@ruby-lang.org"]
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.license = "BSD-2-Clause"
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, :=~, :!~, :===, :<=>, :hash].each do |m|
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 && target.respond_to?(m)
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).bind(self).(*args, &block)
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 &&= target.respond_to?(m, include_private)
99
- if r && include_private && !target.respond_to?(m, false)
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
- [:trust, :untrust, :taint, :untaint, :freeze].each do |method|
238
- define_method method do
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.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Hiroshi SHIBATA
8
- autorequire:
9
- bindir: exe
7
+ - Yukihiro Matsumoto
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-06 00:00:00.000000000 Z
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
- - hsbt@ruby-lang.org
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: '0'
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.3
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
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.6.3
7
- before_install: gem install bundler -v 2.0.2
@@ -1,3 +0,0 @@
1
- class Delegator
2
- VERSION = "0.1.0"
3
- end