deadly_serious 1.0.1 → 1.0.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c84a9aa66532d1b19c770ebb1d226855c073fd03
|
4
|
+
data.tar.gz: 9390c5043f135abd7c6a7c02d713853770cc51f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e70c78e33a1ccbdab49e4bca8dff082f63bcae6f3ee57d0586bd46c2b1cf1ad3212e9d881f25b543ee334dcaa34f74810c4f6fc03a1ac9a2406e850f6d670d8
|
7
|
+
data.tar.gz: a7aede2aa595009185a0752906d9958925fd50cc367d5835fb566b49fc41ce1d84f0f2fd03accba0c6ec68eb57d0df85db83dcb96d2123b8f1bd906729805ca8
|
@@ -52,6 +52,11 @@ module DeadlySerious
|
|
52
52
|
spawn_command('cat', reader: reader, writer: pipe)
|
53
53
|
end
|
54
54
|
|
55
|
+
# Spawn an object connected to the last and next components
|
56
|
+
def spawn(an_object, reader: last_pipe, writer: next_pipe)
|
57
|
+
spawn_process(an_object, readers: [reader], writers: [writer])
|
58
|
+
end
|
59
|
+
|
55
60
|
# Spawn a class connected to the last and next components
|
56
61
|
def spawn_class(a_class, *args, reader: last_pipe, writer: next_pipe)
|
57
62
|
spawn_process(a_class, *args, readers: [reader], writers: [writer])
|
@@ -75,7 +80,7 @@ module DeadlySerious
|
|
75
80
|
end
|
76
81
|
|
77
82
|
# Pipe from the last component to a intermediate
|
78
|
-
# file (or pipe) while the
|
83
|
+
# file (or pipe) while the processes continue.
|
79
84
|
#
|
80
85
|
# If a block is provided, it pipes from the last
|
81
86
|
# component INTO the block.
|
@@ -40,20 +40,21 @@ module DeadlySerious
|
|
40
40
|
#
|
41
41
|
# This is a basic command, use it only if you have
|
42
42
|
# more than one input or output pipe. Otherwise
|
43
|
-
# prefer the
|
44
|
-
#
|
45
|
-
def spawn_process(
|
43
|
+
# prefer the simpler {DeadlySerious::Engine::Commands#spawn_class} or
|
44
|
+
# the {DeadlySerious::Engine::Commands#spawn} methods.
|
45
|
+
def spawn_process(class_or_object, *args, process_name: nil, readers: [last_pipe], writers: [next_pipe])
|
46
46
|
# TODO if we have no readers, alarm! (how about data sources???)
|
47
47
|
# TODO if we have no readers, and this is the first process, read from STDIN
|
48
48
|
# TODO if we have no writers, alarm! (how about data sinks???)
|
49
49
|
# TODO if we have no writers, and this is the last process, write to STDOUT
|
50
|
+
process_name ||= class_or_object.respond_to?(:name) ? class_or_object.name : class_or_object.to_s
|
50
51
|
writers.each { |writer| create_pipe(writer) }
|
51
52
|
@pids << fork do
|
52
53
|
begin
|
53
54
|
set_process_name(process_name, readers, writers)
|
54
55
|
# TODO Change this to not modify "a_class", so we can pass instances too
|
55
|
-
|
56
|
-
the_object
|
56
|
+
the_object = Class === class_or_object ? class_or_object.new : class_or_object
|
57
|
+
append_open_io_if_needed(the_object)
|
57
58
|
the_object.run(*args, readers: readers, writers: writers)
|
58
59
|
rescue Errno::EPIPE # Broken Pipe, no problem
|
59
60
|
# Ignore
|
@@ -111,8 +112,10 @@ module DeadlySerious
|
|
111
112
|
|
112
113
|
private
|
113
114
|
|
114
|
-
def append_open_io_if_needed(
|
115
|
-
|
115
|
+
def append_open_io_if_needed(an_object)
|
116
|
+
class << an_object
|
117
|
+
prepend OpenIo
|
118
|
+
end
|
116
119
|
end
|
117
120
|
|
118
121
|
def create_pipe(pipe_name)
|
@@ -147,11 +150,7 @@ module DeadlySerious
|
|
147
150
|
end
|
148
151
|
|
149
152
|
def set_process_name(name, readers, writers)
|
150
|
-
$0 =
|
151
|
-
end
|
152
|
-
|
153
|
-
def self.dasherize(a_string)
|
154
|
-
a_string.gsub(/(.)([A-Z])/, '\1-\2').downcase.gsub(/\W+/, '-')
|
153
|
+
$0 = format('(%s)-->[%s]-->(%s)', readers.join(', '), name, writers.join(' '))
|
155
154
|
end
|
156
155
|
end
|
157
156
|
end
|
@@ -46,6 +46,27 @@ describe Commands do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
describe '#spawn' do
|
50
|
+
|
51
|
+
class TestTouch
|
52
|
+
def initialize(file)
|
53
|
+
@file = file
|
54
|
+
end
|
55
|
+
def run(readers:, writers:)
|
56
|
+
`touch #{@file}`
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'executes an object' do
|
61
|
+
pipeline = Pipeline.new do |p|
|
62
|
+
p.spawn(TestTouch.new(test_file))
|
63
|
+
end
|
64
|
+
expect(test_file).to_not exists
|
65
|
+
pipeline.run
|
66
|
+
expect(test_file).to exists
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
49
70
|
describe '#spawn_lambda' do
|
50
71
|
it 'executes a lambda' do
|
51
72
|
pipeline = Pipeline.new do |p|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deadly_serious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronie Uliana
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|