io-tee 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.rspec +1 -0
- data/.rubocop.yml +2 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +61 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc/why-sleep.md +8 -0
- data/lib/io/tee.rb +21 -0
- data/lib/io/tee/version.rb +3 -0
- data/ruby-io-tee.gemspec +27 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e3da8765f31c2824b74e39b12beb5b4c93db903fb9228e98b99d58755c07a07c
|
4
|
+
data.tar.gz: a911b94bb292901a963b404803b0eb5a141d0064724eb6bdf4d75cfda55dc165
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f0685be0b8390895597146d053265e4cfbb19963c03d5961ff351c138fe2033c6c50f50c782b1bb3da879217e40d703b74a9770b71c001fb04a4974086905e60
|
7
|
+
data.tar.gz: ee8934914afb360f171e58b8b27ed604f05d6b338c5c7694a09f622d93f39c3770c6493e0e08413d820d2e6e9680e8d7828ba9ccdf12a2376ad24f59e6bb0608
|
data/.gitignore
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion (use of CocoaPods):
|
20
|
+
#
|
21
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
22
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
23
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
24
|
+
#
|
25
|
+
# vendor/Pods/
|
26
|
+
|
27
|
+
## Documentation cache and generated files:
|
28
|
+
/.yardoc/
|
29
|
+
/_yardoc/
|
30
|
+
/rdoc/
|
31
|
+
|
32
|
+
## Environment normalization:
|
33
|
+
/.bundle/
|
34
|
+
/vendor/bundle
|
35
|
+
/lib/bundler/man/
|
36
|
+
|
37
|
+
# for a library or gem, you might want to ignore these files since the code is
|
38
|
+
# intended to run in multiple environments; otherwise, check them in:
|
39
|
+
Gemfile.lock
|
40
|
+
.ruby-version
|
41
|
+
.ruby-gemset
|
42
|
+
|
43
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
44
|
+
# .rvmrc
|
45
|
+
|
46
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
47
|
+
# .rubocop-https?--*
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Daniel Vartanov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
IO::Tee
|
2
|
+
=======
|
3
|
+
|
4
|
+
Copies stdout (or any other IO stream) contents to a file or another stream. Works with subprocesses too.
|
5
|
+
|
6
|
+
### Example 1
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
# io-tee-demo.rb
|
10
|
+
require 'io/tee'
|
11
|
+
|
12
|
+
$stdout.tee('output.log')
|
13
|
+
|
14
|
+
puts "Hello, world!"
|
15
|
+
```
|
16
|
+
|
17
|
+
`$stdout` is effectively copied into file `output.log` **while still being streamed as a standard output**.
|
18
|
+
|
19
|
+
```
|
20
|
+
$ ruby io-tee-demo.rb
|
21
|
+
Hello, world!
|
22
|
+
|
23
|
+
$ cat output.log
|
24
|
+
Hello, world!
|
25
|
+
```
|
26
|
+
|
27
|
+
|
28
|
+
### Example 2
|
29
|
+
|
30
|
+
Obviously it works with more than one stream copied into the same file
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
# io-tee-demo.rb
|
34
|
+
require 'io/tee'
|
35
|
+
|
36
|
+
$stdout.tee('full-output.log')
|
37
|
+
$stderr.tee('full-output.log')
|
38
|
+
|
39
|
+
puts 'Hello, world'
|
40
|
+
$stderr.puts '[DEBUG] Debug info'
|
41
|
+
```
|
42
|
+
|
43
|
+
One can suppress stderr during execution but still get it logged into a file alongside stdout
|
44
|
+
|
45
|
+
```
|
46
|
+
$ ruby io-tee-demo.rb 2> /dev/null
|
47
|
+
Hello, world
|
48
|
+
|
49
|
+
$ cat full-output.log
|
50
|
+
Hello, world
|
51
|
+
[DEBUG] Debug info
|
52
|
+
```
|
53
|
+
|
54
|
+
Append or overwrite
|
55
|
+
-------------------
|
56
|
+
|
57
|
+
A keyword argument of `append: false` can be passed to the `IO#tee`
|
58
|
+
method in order to overwrite the given file upon start of writing.
|
59
|
+
|
60
|
+
|
61
|
+
Sponsored by [Veeqo](https://veeqo.com)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby/io/tee"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/doc/why-sleep.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Why `sleep` is used in the code and in tests?
|
2
|
+
=============================================
|
3
|
+
|
4
|
+
`tee` is expected to complete processing of all available (buffered)
|
5
|
+
data upon SIGTERM signal, but it doesn't do that, there is just no way
|
6
|
+
to synchronise with the moment when all given input is processed,
|
7
|
+
therefore the use of `sleep` is justified. It is the weakest spot of
|
8
|
+
this gem, suggestions are obviously welcome.
|
data/lib/io/tee.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'io/tee/version'
|
2
|
+
|
3
|
+
module IO::Tee
|
4
|
+
def tee(filename, append: true)
|
5
|
+
append_argument = append ? '--append' : ''
|
6
|
+
tee_cmd = "tee #{append_argument} #{filename}"
|
7
|
+
|
8
|
+
tee_output, tee_input = IO.pipe
|
9
|
+
tee_pid = Process.spawn tee_cmd, in: tee_output, out: self
|
10
|
+
|
11
|
+
reopen(tee_input)
|
12
|
+
|
13
|
+
at_exit do
|
14
|
+
sleep 0.05 # see doc/why-sleep.md
|
15
|
+
Process.kill('TERM', tee_pid)
|
16
|
+
Process.waitpid(tee_pid)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
IO.class_eval { include IO::Tee }
|
data/ruby-io-tee.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'lib/io/tee/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "io-tee"
|
5
|
+
spec.version = IO::Tee::VERSION
|
6
|
+
spec.authors = ["Daniel Vartanov"]
|
7
|
+
spec.email = ["dan@vartanov.net"]
|
8
|
+
|
9
|
+
spec.summary = %q{Copies stdout (or any other IO stream) contents to a file or another stream. Works with subprocesses too.}
|
10
|
+
spec.homepage = "https://github.com/DanielVartanov/ruby-io-tee"
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
spec.metadata["source_code_uri"] = "https://github.com/DanielVartanov/ruby-io-tee"
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency 'rspec', '~>3'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: io-tee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Vartanov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- dan@vartanov.net
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- ".rspec"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/console
|
42
|
+
- bin/setup
|
43
|
+
- doc/why-sleep.md
|
44
|
+
- lib/io/tee.rb
|
45
|
+
- lib/io/tee/version.rb
|
46
|
+
- ruby-io-tee.gemspec
|
47
|
+
homepage: https://github.com/DanielVartanov/ruby-io-tee
|
48
|
+
licenses:
|
49
|
+
- MIT
|
50
|
+
metadata:
|
51
|
+
homepage_uri: https://github.com/DanielVartanov/ruby-io-tee
|
52
|
+
source_code_uri: https://github.com/DanielVartanov/ruby-io-tee
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.3.0
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubygems_version: 3.1.2
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: Copies stdout (or any other IO stream) contents to a file or another stream.
|
72
|
+
Works with subprocesses too.
|
73
|
+
test_files: []
|