async 1.13.1 → 1.14.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: 0dc13bfa45d6862be04e8637de5659cbb2feca8a52239a2161863437686d89bf
4
- data.tar.gz: 28d916223fa4402c0839d6652937b987bb14fe53f2fbb62d9313ee191b6bba95
3
+ metadata.gz: e95eca0cff51fba91c446924485001f6bd9d63978d92a15b583bbb8916b7c53b
4
+ data.tar.gz: 463002c552022842360fb031aee28c6286ed7af44761e3e8e55b60c40f1094bb
5
5
  SHA512:
6
- metadata.gz: 371ee258edbe6128ca555b2a1e2b5551acdd3921161121343a7c6ce953c8bb9681c38c794b264037d82ee31e6986e5294ebf448920c6722df5edd6e331756b29
7
- data.tar.gz: 22a1383658c19fc3e300f9ebe5760981a8ba16c7ff2a33bf5dc86a2864ad9c1fc876264137823e95c01440acc8f50a29dc65bf8daacc4bf012922fae2cf9fe23
6
+ metadata.gz: 8d2848633ef85c07e88321c1cc5f4eb890fc53eb66c973dcf182ab5b535fa211b3493d1a265500c83a359bcd673912ea9b77a076e0c818add4ad82b7d5b35a11
7
+ data.tar.gz: 9814c99bbdb06a4993aefd573cf77795d813ee0f129d93cd7df1cc29522cd4f2b11b212a4d9c91d45bdd9f78114ee21ca55dac0fa51438a877124e08e69dd382
@@ -89,32 +89,39 @@ module Async
89
89
  end
90
90
 
91
91
  def format(subject = nil, *arguments, &block)
92
+ buffer = StringIO.new
92
93
  prefix = time_offset_prefix
93
94
  indent = " " * prefix.size
94
95
 
95
- if block_given?
96
- arguments << yield
97
- end
98
-
99
96
  if subject
100
- format_subject(prefix, subject)
97
+ format_subject(prefix, subject, output: buffer)
101
98
  end
102
99
 
103
100
  arguments.each do |argument|
104
- format_argument(indent, argument)
101
+ format_argument(indent, argument, output: buffer)
102
+ end
103
+
104
+ if block_given?
105
+ if block.arity.zero?
106
+ format_argument(indent, yield, output: buffer)
107
+ else
108
+ yield(buffer, @terminal)
109
+ end
105
110
  end
111
+
112
+ @output.write buffer.string
106
113
  end
107
114
 
108
- def format_argument(prefix, argument)
115
+ def format_argument(prefix, argument, output: @output)
109
116
  if argument.is_a? Exception
110
- format_exception(prefix, argument)
117
+ format_exception(prefix, argument, output: output)
111
118
  else
112
- format_value(prefix, argument)
119
+ format_value(prefix, argument, output: output)
113
120
  end
114
121
  end
115
122
 
116
- def format_exception(indent, exception, prefix = nil, pwd: Dir.pwd)
117
- @output.puts "#{indent}| #{prefix}#{@exception_title_style}#{exception.class}#{@reset_style}: #{exception}"
123
+ def format_exception(indent, exception, prefix = nil, pwd: Dir.pwd, output: @output)
124
+ output.puts "#{indent}| #{prefix}#{@exception_title_style}#{exception.class}#{@reset_style}: #{exception}"
118
125
 
119
126
  exception.backtrace.each_with_index do |line, index|
120
127
  path, offset, message = line.split(":")
@@ -122,22 +129,26 @@ module Async
122
129
  # Make the path a bit more readable
123
130
  path.gsub!(/^#{pwd}\//, "./")
124
131
 
125
- @output.puts "#{indent}| #{index == 0 ? "→" : " "} #{@exception_line_style}#{path}:#{offset}#{@reset_style} #{message}"
132
+ output.puts "#{indent}| #{index == 0 ? "→" : " "} #{@exception_line_style}#{path}:#{offset}#{@reset_style} #{message}"
126
133
  end
127
134
 
128
135
  if exception.cause
129
- @output.puts "#{indent}|"
136
+ output.puts "#{indent}|"
130
137
 
131
- format_exception(indent, exception.cause, "Caused by ", pwd: pwd)
138
+ format_exception(indent, exception.cause, "Caused by ", pwd: pwd, output: output)
132
139
  end
133
140
  end
134
141
 
135
- def format_subject(prefix, subject)
136
- @output.puts "#{@prefix_style}#{prefix}: #{@subject_style}#{subject}#{@reset_style}"
142
+ def format_subject(prefix, subject, output: @output)
143
+ output.puts "#{@prefix_style}#{prefix}: #{@subject_style}#{subject}#{@reset_style}"
137
144
  end
138
145
 
139
- def format_value(indent, value)
140
- @output.puts "#{indent}: #{value}"
146
+ def format_value(indent, value, output: @output)
147
+ string = value.to_s
148
+
149
+ string.each_line do |line|
150
+ output.puts "#{indent}: #{line}"
151
+ end
141
152
  end
142
153
 
143
154
  def time_offset_prefix
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.13.1"
22
+ VERSION = "1.14.0"
23
23
  end
@@ -36,6 +36,14 @@ RSpec.describe Async::Logger do
36
36
 
37
37
  expect(output.string).to_not include message
38
38
  end
39
+
40
+ it "can log to buffer" do
41
+ subject.info do |buffer|
42
+ buffer << message
43
+ end
44
+
45
+ expect(output.string).to include message
46
+ end
39
47
  end
40
48
 
41
49
  described_class::LEVELS.each do |name, level|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.1
4
+ version: 1.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-15 00:00:00.000000000 Z
11
+ date: 2019-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -124,7 +124,6 @@ files:
124
124
  - lib/async/debug/monitor.rb
125
125
  - lib/async/debug/selector.rb
126
126
  - lib/async/logger.rb
127
- - lib/async/measure.rb
128
127
  - lib/async/node.rb
129
128
  - lib/async/notification.rb
130
129
  - lib/async/queue.rb
@@ -1,37 +0,0 @@
1
- # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
20
-
21
- require 'benchmark'
22
-
23
- module Async
24
- def self.measure(*args, threshold: 1.0, &block)
25
- result = nil
26
-
27
- duration = Benchmark.realtime do
28
- result = yield
29
- end
30
-
31
- return result
32
- ensure
33
- if duration && duration > threshold
34
- warn "#{args.join(' ')} took #{duration}s"
35
- end
36
- end
37
- end