forwardable-extended 2.5.1 → 2.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/lib/forwardable/extended.rb +28 -18
- data/lib/forwardable/extended/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d90dc39d0f23f0acbfa3fb0563db755d1c898f0
|
4
|
+
data.tar.gz: ff31cfc71354d276f702baffd3289cd5d9b2e8a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ac56d19ae6529f9502925b38d919525f66183db7f4ea1ae0a766748aeee4e413d8b9d5137318ca7a956e5f6a5860f4ad325d30746d1618fd339dc29ff02351c
|
7
|
+
data.tar.gz: 1c0eecff649dd33ea319a14aff83814718b1dc46cbc76728ac2a4b513217b64751a703056c35afac8d5bd42210003a89b83ba55183cb3056a3e3029ab022b32e
|
data/Gemfile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
3
|
# Copyright: 2015-2016 Jordon Bedwell - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
source "https://rubygems.org"
|
6
8
|
gem "rake", :require => false
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
3
|
# Copyright: 2015-2016 Jordon Bedwell - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
|
6
8
|
require "luna/rubocop/rake/task"
|
data/lib/forwardable/extended.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
1
2
|
# Frozen-string-literal: true
|
2
3
|
# Copyright: 2015-2016 Jordon Bedwell - MIT License
|
3
4
|
# Encoding: utf-8
|
5
|
+
# ----------------------------------------------------------------------------
|
4
6
|
|
5
7
|
require "forwardable/extended/version"
|
6
8
|
require "forwardable"
|
@@ -8,9 +10,10 @@ require "forwardable"
|
|
8
10
|
module Forwardable
|
9
11
|
module Extended
|
10
12
|
|
13
|
+
# ------------------------------------------------------------------------
|
11
14
|
# Make our methods private on the class, there is no reason for public.
|
12
|
-
#
|
13
|
-
|
15
|
+
# ------------------------------------------------------------------------
|
16
|
+
|
14
17
|
def self.extended(klass)
|
15
18
|
instance_methods.each do |method|
|
16
19
|
klass.private_class_method(
|
@@ -19,10 +22,10 @@ module Forwardable
|
|
19
22
|
end
|
20
23
|
end
|
21
24
|
|
25
|
+
# ------------------------------------------------------------------------
|
22
26
|
# Delegate using a Rails-like interface.
|
23
|
-
#
|
24
|
-
|
25
|
-
# method - the method you are forwarding.
|
27
|
+
# ------------------------------------------------------------------------
|
28
|
+
|
26
29
|
def rb_delegate(method, to: nil, alias_of: method, **kwd)
|
27
30
|
raise ArgumentError, "to must be provided" unless to
|
28
31
|
def_delegator(
|
@@ -30,10 +33,10 @@ module Forwardable
|
|
30
33
|
)
|
31
34
|
end
|
32
35
|
|
36
|
+
# ------------------------------------------------------------------------
|
33
37
|
# Delegate a method to a hash and key.
|
34
|
-
#
|
35
|
-
|
36
|
-
# hash - the hash you are delegating to.
|
38
|
+
# ------------------------------------------------------------------------
|
39
|
+
|
37
40
|
def def_hash_delegator(hash, method, key: method, **kwd)
|
38
41
|
prefix, suffix, wrap = prepare_delegate(**kwd)
|
39
42
|
|
@@ -61,10 +64,10 @@ module Forwardable
|
|
61
64
|
STR
|
62
65
|
end
|
63
66
|
|
67
|
+
# ------------------------------------------------------------------------
|
64
68
|
# Delegate a method to an instance variable.
|
65
|
-
#
|
66
|
-
|
67
|
-
# Note: If you are not doing booleans then don't bother with this.
|
69
|
+
# ------------------------------------------------------------------------
|
70
|
+
|
68
71
|
def def_ivar_delegator(ivar, alias_ = ivar, **kwd)
|
69
72
|
prefix, suffix, wrap = prepare_delegate(**kwd)
|
70
73
|
|
@@ -92,11 +95,10 @@ module Forwardable
|
|
92
95
|
STR
|
93
96
|
end
|
94
97
|
|
95
|
-
#
|
96
|
-
# alias_ - the name of the method on the current object.
|
97
|
-
# args - arguments to pass to the method. Note: these are inspected.
|
98
|
+
# ------------------------------------------------------------------------
|
98
99
|
# Like def_delegator but allows you to send args and do other stuff.
|
99
|
-
#
|
100
|
+
# ------------------------------------------------------------------------
|
101
|
+
|
100
102
|
def def_modern_delegator(accessor, method, alias_ = method, args: [], **kwd)
|
101
103
|
args = [args].flatten.compact.map(&:to_s).unshift("").join(", ")
|
102
104
|
prefix, suffix, wrap = prepare_delegate(**kwd)
|
@@ -125,7 +127,10 @@ module Forwardable
|
|
125
127
|
STR
|
126
128
|
end
|
127
129
|
|
130
|
+
# ------------------------------------------------------------------------
|
128
131
|
# Wraps around traditional delegation and modern delegation.
|
132
|
+
# ------------------------------------------------------------------------
|
133
|
+
|
129
134
|
def def_delegator(accessor, method, alias_ = method, **kwd)
|
130
135
|
kwd, alias_ = alias_, method if alias_.is_a?(Hash) && !kwd.any?
|
131
136
|
|
@@ -146,7 +151,10 @@ module Forwardable
|
|
146
151
|
end
|
147
152
|
end
|
148
153
|
|
154
|
+
# ------------------------------------------------------------------------
|
149
155
|
# Create multiple delegates at once.
|
156
|
+
# ------------------------------------------------------------------------
|
157
|
+
|
150
158
|
def def_delegators(accessor, *methods)
|
151
159
|
kwd = methods.shift if methods.first.is_a?(Hash)
|
152
160
|
kwd = methods.pop if methods. last.is_a?(Hash)
|
@@ -157,10 +165,12 @@ module Forwardable
|
|
157
165
|
end
|
158
166
|
end
|
159
167
|
|
168
|
+
# ------------------------------------------------------------------------
|
160
169
|
# Prepares a delegate and it's few arguments.
|
161
|
-
#
|
162
|
-
|
163
|
-
private
|
170
|
+
# ------------------------------------------------------------------------
|
171
|
+
|
172
|
+
private
|
173
|
+
def prepare_delegate(wrap: nil, bool: false)
|
164
174
|
prefix = (bool == :reverse ? "!!!" : "!!") if bool
|
165
175
|
wrap = "self.class.new" if wrap.is_a?(TrueClass)
|
166
176
|
suffix = "?" if bool
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: forwardable-extended
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.
|
4
|
+
version: 2.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jordon Bedwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Forwardable with hash, and instance variable extensions.
|
14
14
|
email:
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
44
|
rubyforge_project:
|
45
|
-
rubygems_version: 2.
|
45
|
+
rubygems_version: 2.6.2
|
46
46
|
signing_key:
|
47
47
|
specification_version: 4
|
48
48
|
summary: Forwardable with hash, and instance variable extensions.
|