forwardable-extended 2.5.3 → 2.6.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
  SHA1:
3
- metadata.gz: 9d90dc39d0f23f0acbfa3fb0563db755d1c898f0
4
- data.tar.gz: ff31cfc71354d276f702baffd3289cd5d9b2e8a8
3
+ metadata.gz: 5a63d4f78c993a050c8b1cc6aa077296fa7acab3
4
+ data.tar.gz: dbd35851e146d851ed4d3b1f0db85a5bfb432666
5
5
  SHA512:
6
- metadata.gz: 8ac56d19ae6529f9502925b38d919525f66183db7f4ea1ae0a766748aeee4e413d8b9d5137318ca7a956e5f6a5860f4ad325d30746d1618fd339dc29ff02351c
7
- data.tar.gz: 1c0eecff649dd33ea319a14aff83814718b1dc46cbc76728ac2a4b513217b64751a703056c35afac8d5bd42210003a89b83ba55183cb3056a3e3029ab022b32e
6
+ metadata.gz: d4b9c2dc38d4420b791309886c545b35f1fe9b3ad0211365582f678daed1dee9e84416f39c10949ecbc5421cf85f638cd47068d081d8d74ca75ff246fb3e0764
7
+ data.tar.gz: 0508f825a4a79e5bb26da05da2489646b741cd86dc8ee51cc956b5d1ba1e2901f10ecfc4513048a03244acea35781f7ee2ceb805c1f6a110db80338f4dbc0583
@@ -46,14 +46,14 @@ module Forwardable
46
46
  )
47
47
  end
48
48
 
49
- class_eval <<-STR, __FILE__, __LINE__ - 9
49
+ class_eval delegate_debug(<<-STR), __FILE__, __LINE__ - 9
50
50
  def #{method}#{suffix}(*args)
51
51
  #{wrap}(
52
52
  #{prefix}#{hash}[#{key.inspect}]
53
53
  )
54
54
 
55
55
  rescue Exception
56
- unless Forwardable.debug
56
+ if !Forwardable.debug && $@ && $@.respond_to?(:delete_if)
57
57
  $@.delete_if do |source|
58
58
  source =~ %r"#{Regexp.escape(__FILE__)}"o
59
59
  end
@@ -77,14 +77,14 @@ module Forwardable
77
77
  )
78
78
  end
79
79
 
80
- class_eval <<-STR, __FILE__, __LINE__ - 9
80
+ class_eval delegate_debug(<<-STR), __FILE__, __LINE__ - 9
81
81
  def #{alias_.to_s.gsub(/\A@/, "")}#{suffix}
82
82
  #{wrap}(
83
83
  #{prefix}#{ivar}
84
84
  )
85
85
 
86
86
  rescue Exception
87
- unless Forwardable.debug
87
+ if !Forwardable.debug && $@ && $@.respond_to?(:delete_if)
88
88
  $@.delete_if do |source|
89
89
  source =~ %r"#{Regexp.escape(__FILE__)}"o
90
90
  end
@@ -99,24 +99,25 @@ module Forwardable
99
99
  # Like def_delegator but allows you to send args and do other stuff.
100
100
  # ------------------------------------------------------------------------
101
101
 
102
- def def_modern_delegator(accessor, method, alias_ = method, args: [], **kwd)
103
- args = [args].flatten.compact.map(&:to_s).unshift("").join(", ")
104
- prefix, suffix, wrap = prepare_delegate(**kwd)
102
+ def def_modern_delegator(accessor, method, alias_ = method, args: \
103
+ { :before => [], :after => [] }, **kwd)
105
104
 
106
- if suffix
107
- alias_ = alias_.to_s.gsub(
108
- /\?$/, ""
109
- )
110
- end
111
-
112
- class_eval <<-STR, __FILE__, __LINE__ - 10
105
+ prefix, suffix, wrap = prepare_delegate(**kwd)
106
+ args = { :before => args } unless args.is_a?(Hash)
107
+ b = [args[:before]].flatten.compact.map(&:to_s).join(", ")
108
+ a = [args[ :after]].flatten.compact.map(&:to_s).join(", ")
109
+ b = b + ", " unless args[:before].nil? || args[:before].empty?
110
+ a = ", " + a unless args[ :after].nil? || args[ :after].empty?
111
+ alias_ = alias_.to_s.gsub(/\?$/, "") if suffix
112
+
113
+ class_eval delegate_debug(<<-STR), __FILE__, __LINE__ - 10
113
114
  def #{alias_}#{suffix}(*args, &block)
114
115
  #{wrap}(#{prefix}#{accessor}.send(
115
- #{method.inspect}#{args}, *args, &block
116
+ #{method.inspect}, #{b}*args#{a}, &block
116
117
  ))
117
118
 
118
119
  rescue Exception
119
- unless Forwardable.debug
120
+ if !Forwardable.debug && $@ && $@.respond_to?(:delete_if)
120
121
  $@.delete_if do |source|
121
122
  source =~ %r"#{Regexp.escape(__FILE__)}"o
122
123
  end
@@ -179,5 +180,23 @@ module Forwardable
179
180
  prefix, suffix, wrap
180
181
  ]
181
182
  end
183
+
184
+ # ------------------------------------------------------------------------
185
+
186
+ private
187
+ def delegate_debug(str)
188
+ if Forwardable.debug && !Forwardable.debug.is_a?(TrueClass)
189
+ then Forwardable.debug.debug(
190
+ str
191
+ )
192
+
193
+ elsif Forwardable.debug
194
+ $stdout.puts(
195
+ "\n# ------\n\n", str
196
+ )
197
+ end
198
+
199
+ str
200
+ end
182
201
  end
183
202
  end
@@ -4,6 +4,6 @@
4
4
 
5
5
  module Forwardable
6
6
  module Extended
7
- VERSION = "2.5.3"
7
+ VERSION = "2.6.0"
8
8
  end
9
9
  end
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.3
4
+ version: 2.6.0
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-19 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Forwardable with hash, and instance variable extensions.
14
14
  email: