forwardable 1.2.0 → 1.3.2
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/forwardable.gemspec +12 -12
- data/lib/forwardable/impl.rb +0 -8
- data/lib/forwardable.rb +26 -16
- metadata +9 -45
- data/.gitignore +0 -8
- data/.travis.yml +0 -6
- data/Gemfile +0 -5
- data/LICENSE.txt +0 -22
- data/README.md +0 -79
- data/Rakefile +0 -10
- data/bin/console +0 -7
- data/bin/setup +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8729830e9c34626b9912c4ea6424e9edadd6c86d6dc6816ee4c2b1defc5923a1
|
4
|
+
data.tar.gz: 69b7122793c8d0b6dac6a4f03b20c70481f1c1ec3ac4f8641639249d5c7f9024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67bb1876e2ac2da9367b3744332ee376de7ffebeaaf20d7bbc01a5af537d087c4bcbed6eebaad140a4c20cd1f8dafa46f1250a14c8617e22ee20eda688683045
|
7
|
+
data.tar.gz: 1a244c0a3ce5227258862e7632fd28d224cf1b2d65f9ec67eabb93e2c6369c177a199ea465f366bc5a15d53177ba1b565b591eb6a1c940a4454bb74cc6488d24
|
data/forwardable.gemspec
CHANGED
@@ -1,26 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
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
|
6
8
|
end
|
7
9
|
|
8
10
|
Gem::Specification.new do |spec|
|
9
|
-
spec.name =
|
10
|
-
spec.version =
|
11
|
+
spec.name = name
|
12
|
+
spec.version = version
|
11
13
|
spec.authors = ["Keiju ISHITSUKA"]
|
12
14
|
spec.email = ["keiju@ruby-lang.org"]
|
13
15
|
|
14
16
|
spec.summary = %q{Provides delegation of specified methods to a designated object.}
|
15
17
|
spec.description = %q{Provides delegation of specified methods to a designated object.}
|
16
18
|
spec.homepage = "https://github.com/ruby/forwardable"
|
17
|
-
spec.
|
19
|
+
spec.licenses = ["Ruby", "BSD-2-Clause"]
|
18
20
|
|
19
|
-
spec.
|
21
|
+
spec.required_ruby_version = '>= 2.4.0'
|
22
|
+
spec.files = ["forwardable.gemspec", "lib/forwardable.rb", "lib/forwardable/impl.rb"]
|
20
23
|
spec.bindir = "exe"
|
21
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
25
|
spec.require_paths = ["lib"]
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler"
|
25
|
-
spec.add_development_dependency "rake"
|
26
26
|
end
|
data/lib/forwardable/impl.rb
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
# :stopdoc:
|
2
2
|
module Forwardable
|
3
|
-
FILE_REGEXP = %r"#{Regexp.quote(File.dirname(__FILE__))}"
|
4
|
-
FILTER_EXCEPTION = <<-'END'
|
5
|
-
|
6
|
-
rescue ::Exception
|
7
|
-
$@.delete_if {|s| ::Forwardable::FILE_REGEXP =~ s} unless ::Forwardable::debug
|
8
|
-
::Kernel::raise
|
9
|
-
END
|
10
|
-
|
11
3
|
def self._valid_method?(method)
|
12
4
|
catch {|tag|
|
13
5
|
eval("BEGIN{throw tag}; ().#{method}", binding, __FILE__, __LINE__)
|
data/lib/forwardable.rb
CHANGED
@@ -57,10 +57,9 @@
|
|
57
57
|
#
|
58
58
|
# == Another example
|
59
59
|
#
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
# interface, even if much of it isn't needed.
|
60
|
+
# You could use Forwardable as an alternative to inheritance, when you don't want
|
61
|
+
# to inherit all methods from the superclass. For instance, here is how you might
|
62
|
+
# add a range of +Array+ instance methods to a new class +Queue+:
|
64
63
|
#
|
65
64
|
# class Queue
|
66
65
|
# extend Forwardable
|
@@ -113,7 +112,7 @@ module Forwardable
|
|
113
112
|
require 'forwardable/impl'
|
114
113
|
|
115
114
|
# Version of +forwardable.rb+
|
116
|
-
VERSION = "1.2
|
115
|
+
VERSION = "1.3.2"
|
117
116
|
FORWARDABLE_VERSION = VERSION
|
118
117
|
|
119
118
|
@debug = nil
|
@@ -123,7 +122,8 @@ module Forwardable
|
|
123
122
|
end
|
124
123
|
|
125
124
|
# Takes a hash as its argument. The key is a symbol or an array of
|
126
|
-
# symbols. These symbols correspond to method names
|
125
|
+
# symbols. These symbols correspond to method names, instance variable
|
126
|
+
# names, or constant names (see def_delegator). The value is
|
127
127
|
# the accessor to which the methods will be delegated.
|
128
128
|
#
|
129
129
|
# :call-seq:
|
@@ -152,18 +152,21 @@ module Forwardable
|
|
152
152
|
# def_delegator :@records, :map
|
153
153
|
#
|
154
154
|
def def_instance_delegators(accessor, *methods)
|
155
|
-
methods.
|
156
|
-
|
157
|
-
for method in methods
|
155
|
+
methods.each do |method|
|
156
|
+
next if /\A__(?:send|id)__\z/ =~ method
|
158
157
|
def_instance_delegator(accessor, method)
|
159
158
|
end
|
160
159
|
end
|
161
160
|
|
162
161
|
# Define +method+ as delegator instance method with an optional
|
163
162
|
# alias name +ali+. Method calls to +ali+ will be delegated to
|
164
|
-
# +accessor.method+.
|
163
|
+
# +accessor.method+. +accessor+ should be a method name, instance
|
164
|
+
# variable name, or constant name. Use the full path to the
|
165
|
+
# constant if providing the constant name.
|
166
|
+
# Returns the name of the method defined.
|
165
167
|
#
|
166
168
|
# class MyQueue
|
169
|
+
# CONST = 1
|
167
170
|
# extend Forwardable
|
168
171
|
# attr_reader :queue
|
169
172
|
# def initialize
|
@@ -171,18 +174,23 @@ module Forwardable
|
|
171
174
|
# end
|
172
175
|
#
|
173
176
|
# def_delegator :@queue, :push, :mypush
|
177
|
+
# def_delegator 'MyQueue::CONST', :to_i
|
174
178
|
# end
|
175
179
|
#
|
176
180
|
# q = MyQueue.new
|
177
181
|
# q.mypush 42
|
178
182
|
# q.queue #=> [42]
|
179
183
|
# q.push 23 #=> NoMethodError
|
184
|
+
# q.to_i #=> 1
|
180
185
|
#
|
181
186
|
def def_instance_delegator(accessor, method, ali = method)
|
182
187
|
gen = Forwardable._delegator_method(self, accessor, method, ali)
|
183
188
|
|
184
189
|
# If it's not a class or module, it's an instance
|
185
|
-
|
190
|
+
mod = Module === self ? self : singleton_class
|
191
|
+
ret = mod.module_eval(&gen)
|
192
|
+
mod.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
|
193
|
+
ret
|
186
194
|
end
|
187
195
|
|
188
196
|
alias delegate instance_delegate
|
@@ -222,7 +230,7 @@ module Forwardable
|
|
222
230
|
#{pre}
|
223
231
|
begin
|
224
232
|
#{accessor}
|
225
|
-
end#{method_call}
|
233
|
+
end#{method_call}
|
226
234
|
end
|
227
235
|
end
|
228
236
|
end;
|
@@ -284,9 +292,8 @@ module SingleForwardable
|
|
284
292
|
# def_delegator :@records, :map
|
285
293
|
#
|
286
294
|
def def_single_delegators(accessor, *methods)
|
287
|
-
methods.
|
288
|
-
|
289
|
-
for method in methods
|
295
|
+
methods.each do |method|
|
296
|
+
next if /\A__(?:send|id)__\z/ =~ method
|
290
297
|
def_single_delegator(accessor, method)
|
291
298
|
end
|
292
299
|
end
|
@@ -297,10 +304,13 @@ module SingleForwardable
|
|
297
304
|
# Defines a method _method_ which delegates to _accessor_ (i.e. it calls
|
298
305
|
# the method of the same name in _accessor_). If _new_name_ is
|
299
306
|
# provided, it is used as the name for the delegate method.
|
307
|
+
# Returns the name of the method defined.
|
300
308
|
def def_single_delegator(accessor, method, ali = method)
|
301
309
|
gen = Forwardable._delegator_method(self, accessor, method, ali)
|
302
310
|
|
303
|
-
instance_eval(&gen)
|
311
|
+
ret = instance_eval(&gen)
|
312
|
+
singleton_class.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
|
313
|
+
ret
|
304
314
|
end
|
305
315
|
|
306
316
|
alias delegate single_delegate
|
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forwardable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keiju ISHITSUKA
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
11
|
+
date: 2020-12-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: Provides delegation of specified methods to a designated object.
|
42
14
|
email:
|
43
15
|
- keiju@ruby-lang.org
|
@@ -45,22 +17,15 @@ executables: []
|
|
45
17
|
extensions: []
|
46
18
|
extra_rdoc_files: []
|
47
19
|
files:
|
48
|
-
- ".gitignore"
|
49
|
-
- ".travis.yml"
|
50
|
-
- Gemfile
|
51
|
-
- LICENSE.txt
|
52
|
-
- README.md
|
53
|
-
- Rakefile
|
54
|
-
- bin/console
|
55
|
-
- bin/setup
|
56
20
|
- forwardable.gemspec
|
57
21
|
- lib/forwardable.rb
|
58
22
|
- lib/forwardable/impl.rb
|
59
23
|
homepage: https://github.com/ruby/forwardable
|
60
24
|
licenses:
|
25
|
+
- Ruby
|
61
26
|
- BSD-2-Clause
|
62
27
|
metadata: {}
|
63
|
-
post_install_message:
|
28
|
+
post_install_message:
|
64
29
|
rdoc_options: []
|
65
30
|
require_paths:
|
66
31
|
- lib
|
@@ -68,16 +33,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
33
|
requirements:
|
69
34
|
- - ">="
|
70
35
|
- !ruby/object:Gem::Version
|
71
|
-
version:
|
36
|
+
version: 2.4.0
|
72
37
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
38
|
requirements:
|
74
39
|
- - ">="
|
75
40
|
- !ruby/object:Gem::Version
|
76
41
|
version: '0'
|
77
42
|
requirements: []
|
78
|
-
|
79
|
-
|
80
|
-
signing_key:
|
43
|
+
rubygems_version: 3.2.2
|
44
|
+
signing_key:
|
81
45
|
specification_version: 4
|
82
46
|
summary: Provides delegation of specified methods to a designated object.
|
83
47
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
|
2
|
-
|
3
|
-
Redistribution and use in source and binary forms, with or without
|
4
|
-
modification, are permitted provided that the following conditions
|
5
|
-
are met:
|
6
|
-
1. Redistributions of source code must retain the above copyright
|
7
|
-
notice, this list of conditions and the following disclaimer.
|
8
|
-
2. Redistributions in binary form must reproduce the above copyright
|
9
|
-
notice, this list of conditions and the following disclaimer in the
|
10
|
-
documentation and/or other materials provided with the distribution.
|
11
|
-
|
12
|
-
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
13
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
14
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
15
|
-
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
16
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
17
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
18
|
-
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
19
|
-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
20
|
-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
21
|
-
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
22
|
-
SUCH DAMAGE.
|
data/README.md
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# Forwardable
|
2
|
-
|
3
|
-
The Forwardable module provides delegation of specified methods to a designated object, using the methods #def_delegator and #def_delegators.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
Add this line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'forwardable'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
$ bundle
|
16
|
-
|
17
|
-
Or install it yourself as:
|
18
|
-
|
19
|
-
$ gem install forwardable
|
20
|
-
|
21
|
-
## Usage
|
22
|
-
|
23
|
-
For example, say you have a class RecordCollection which contains an array <tt>@records</tt>. You could provide the lookup ethod `#record_number()`, which simply calls #[] on the <tt>@records</tt> array, like this:
|
24
|
-
|
25
|
-
```
|
26
|
-
require 'forwardable'
|
27
|
-
|
28
|
-
class RecordCollection
|
29
|
-
attr_accessor :records
|
30
|
-
extend Forwardable
|
31
|
-
def_delegator :@records, :[], :record_number
|
32
|
-
end
|
33
|
-
```
|
34
|
-
|
35
|
-
We can use the lookup method like so:
|
36
|
-
|
37
|
-
```
|
38
|
-
r = RecordCollection.new
|
39
|
-
r.records = [4,5,6]
|
40
|
-
r.record_number(0) # => 4
|
41
|
-
```
|
42
|
-
|
43
|
-
Further, if you wish to provide the methods #size, #<<, and #map, all of which delegate to @records, this is how you can do it:
|
44
|
-
|
45
|
-
```
|
46
|
-
class RecordCollection # re-open RecordCollection class
|
47
|
-
def_delegators :@records, :size, :<<, :map
|
48
|
-
end
|
49
|
-
|
50
|
-
r = RecordCollection.new
|
51
|
-
r.records = [1,2,3]
|
52
|
-
r.record_number(0) # => 1
|
53
|
-
r.size # => 3
|
54
|
-
r << 4 # => [1, 2, 3, 4]
|
55
|
-
r.map { |x| x * 2 } # => [2, 4, 6, 8]
|
56
|
-
```
|
57
|
-
|
58
|
-
You can even extend regular objects with Forwardable.
|
59
|
-
|
60
|
-
```
|
61
|
-
my_hash = Hash.new
|
62
|
-
my_hash.extend Forwardable # prepare object for delegation
|
63
|
-
my_hash.def_delegator "STDOUT", "puts" # add delegation for STDOUT.puts()
|
64
|
-
my_hash.puts "Howdy!"
|
65
|
-
```
|
66
|
-
|
67
|
-
## Development
|
68
|
-
|
69
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
70
|
-
|
71
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
72
|
-
|
73
|
-
## Contributing
|
74
|
-
|
75
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/forwardable.
|
76
|
-
|
77
|
-
## License
|
78
|
-
|
79
|
-
The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
|
data/Rakefile
DELETED
data/bin/console
DELETED