pp 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pp.rb +33 -18
  3. data/pp.gemspec +3 -1
  4. metadata +18 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7781a81818bc667adae58438a03341d3a24aa6e5632739a0745ebd4c1e01c374
4
- data.tar.gz: 2110bf8b8a49cbe79a8cef6882391cacb6ca98f235b342923fc1bf8f82c4b71c
3
+ metadata.gz: 80f1e5fc76139b08c104dce9adb682eb3220e95d36e6fcce17667187f39831f9
4
+ data.tar.gz: 620cb2b296e74d060966c7162169428ff673fbef6f63880eb4c8514706bbccc0
5
5
  SHA512:
6
- metadata.gz: f3edf21a3229d2909ff2a936baa0f1cca0728b150d788fc6db08a1bfc0c8ff2868169f0fda013f16ba074e01a6f4be5c6bca77a90e12f067fc24dd3a9a181f93
7
- data.tar.gz: 7c85c18274cd2717c2fd211fb41b3bf9d8424fd382ff8bd19a3799570a4c986b29a840be6d7d0c1ce9b47fbd126fe3b0f98525e7434232be6de8e899b862b590
6
+ metadata.gz: ba3a712f99b773c8de3eb473bdb5bffe3c4f2e4d1ee57649e7df4380d9994751b47d812c44c3708c66916d82bc7b6669e7e44e95224699fa1a30dd26067f57a4
7
+ data.tar.gz: d2394827137746ffc4bd03323c3245e25b1bd9b3265819be27d510fc7ad3140ab2a6d19e4873ff1e9f51672d0632323c525af3d2fd138c367882426a868988a2
data/lib/pp.rb CHANGED
@@ -89,15 +89,28 @@ class PP < PrettyPrint
89
89
 
90
90
  # :stopdoc:
91
91
  def PP.mcall(obj, mod, meth, *args, &block)
92
- mod.instance_method(meth).bind(obj).call(*args, &block)
92
+ mod.instance_method(meth).bind_call(obj, *args, &block)
93
93
  end
94
94
  # :startdoc:
95
95
 
96
- @sharing_detection = false
97
- class << self
98
- # Returns the sharing detection flag as a boolean value.
99
- # It is false by default.
100
- attr_accessor :sharing_detection
96
+ if defined? ::Ractor
97
+ class << self
98
+ # Returns the sharing detection flag as a boolean value.
99
+ # It is false (nil) by default.
100
+ def sharing_detection
101
+ Ractor.current[:pp_sharing_detection]
102
+ end
103
+ def sharing_detection=(b)
104
+ Ractor.current[:pp_sharing_detection] = b
105
+ end
106
+ end
107
+ else
108
+ @sharing_detection = false
109
+ class << self
110
+ # Returns the sharing detection flag as a boolean value.
111
+ # It is false by default.
112
+ attr_accessor :sharing_detection
113
+ end
101
114
  end
102
115
 
103
116
  module PPMethods
@@ -106,17 +119,17 @@ class PP < PrettyPrint
106
119
  # and preserves the previous set of objects being printed.
107
120
  def guard_inspect_key
108
121
  if Thread.current[:__recursive_key__] == nil
109
- Thread.current[:__recursive_key__] = {}.taint
122
+ Thread.current[:__recursive_key__] = {}.compare_by_identity
110
123
  end
111
124
 
112
125
  if Thread.current[:__recursive_key__][:inspect] == nil
113
- Thread.current[:__recursive_key__][:inspect] = {}.taint
126
+ Thread.current[:__recursive_key__][:inspect] = {}.compare_by_identity
114
127
  end
115
128
 
116
129
  save = Thread.current[:__recursive_key__][:inspect]
117
130
 
118
131
  begin
119
- Thread.current[:__recursive_key__][:inspect] = {}.taint
132
+ Thread.current[:__recursive_key__][:inspect] = {}.compare_by_identity
120
133
  yield
121
134
  ensure
122
135
  Thread.current[:__recursive_key__][:inspect] = save
@@ -149,18 +162,20 @@ class PP < PrettyPrint
149
162
  # Object#pretty_print_cycle is used when +obj+ is already
150
163
  # printed, a.k.a the object reference chain has a cycle.
151
164
  def pp(obj)
152
- id = obj.object_id
165
+ # If obj is a Delegator then use the object being delegated to for cycle
166
+ # detection
167
+ obj = obj.__getobj__ if defined?(::Delegator) and obj.is_a?(::Delegator)
153
168
 
154
- if check_inspect_key(id)
169
+ if check_inspect_key(obj)
155
170
  group {obj.pretty_print_cycle self}
156
171
  return
157
172
  end
158
173
 
159
174
  begin
160
- push_inspect_key(id)
175
+ push_inspect_key(obj)
161
176
  group {obj.pretty_print self}
162
177
  ensure
163
- pop_inspect_key(id) unless PP.sharing_detection
178
+ pop_inspect_key(obj) unless PP.sharing_detection
164
179
  end
165
180
  end
166
181
 
@@ -174,7 +189,7 @@ class PP < PrettyPrint
174
189
  # A convenience method, like object_group, but also reformats the Object's
175
190
  # object_id.
176
191
  def object_address_group(obj, &block)
177
- str = Kernel.instance_method(:to_s).bind(obj).call
192
+ str = Kernel.instance_method(:to_s).bind_call(obj)
178
193
  str.chomp!('>')
179
194
  group(1, str, '>', &block)
180
195
  end
@@ -221,7 +236,7 @@ class PP < PrettyPrint
221
236
  else
222
237
  sep.call
223
238
  end
224
- yield(*v)
239
+ yield(*v, **{})
225
240
  }
226
241
  end
227
242
 
@@ -279,9 +294,9 @@ class PP < PrettyPrint
279
294
  # This module provides predefined #pretty_print methods for some of
280
295
  # the most commonly used built-in classes for convenience.
281
296
  def pretty_print(q)
282
- method_method = Object.instance_method(:method).bind(self)
297
+ umethod_method = Object.instance_method(:method)
283
298
  begin
284
- inspect_method = method_method.call(:inspect)
299
+ inspect_method = umethod_method.bind_call(self, :inspect)
285
300
  rescue NameError
286
301
  end
287
302
  if inspect_method && inspect_method.owner != Kernel
@@ -318,7 +333,7 @@ class PP < PrettyPrint
318
333
  # However, doing this requires that every class that #inspect is called on
319
334
  # implement #pretty_print, or a RuntimeError will be raised.
320
335
  def pretty_print_inspect
321
- if Object.instance_method(:method).bind(self).call(:pretty_print).owner == PP::ObjectMixin
336
+ if Object.instance_method(:method).bind_call(self, :pretty_print).owner == PP::ObjectMixin
322
337
  raise "pretty_print is not overridden for #{self.class}"
323
338
  end
324
339
  PP.singleline_pp(self, ''.dup)
data/pp.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pp"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Tanaka Akira"]
5
5
  spec.email = ["akr@fsij.org"]
6
6
 
@@ -19,4 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.bindir = "exe"
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "prettyprint"
22
24
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prettyprint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Provides a PrettyPrinter for Ruby objects
14
28
  email:
15
29
  - akr@fsij.org
@@ -49,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
63
  - !ruby/object:Gem::Version
50
64
  version: '0'
51
65
  requirements: []
52
- rubygems_version: 3.2.0.rc.1
66
+ rubygems_version: 3.2.2
53
67
  signing_key:
54
68
  specification_version: 4
55
69
  summary: Provides a PrettyPrinter for Ruby objects