deadly_serious 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2fd3b41c8b2b866bb79079d55423d4254e204011
4
- data.tar.gz: 78691ca6aa34dba39caea645dac9b1a8e17e5388
3
+ metadata.gz: c84a9aa66532d1b19c770ebb1d226855c073fd03
4
+ data.tar.gz: 9390c5043f135abd7c6a7c02d713853770cc51f8
5
5
  SHA512:
6
- metadata.gz: 4194e48d8c080d8cae916c1eece98ea295c7968006c709ab2cf1249ff7c9fd7f0e8b5022a123a7b350200efc2443edb91e7b5edb4d1fc6e98a77bf3f2c7b54b7
7
- data.tar.gz: 500af882d4345e4afd70bbd332ffab5a2c641ba4f9f42b381abc73a7314fbea970639641bc28c40e7b1f6027332e31d5ea372ae8aba92541fd871b38209eb6b9
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 processe continue.
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 simplier {DeadlySerious::Engine::Commands#spawn_class}
44
- # method.
45
- def spawn_process(a_class, *args, process_name: a_class.name, readers: [last_pipe], writers: [next_pipe])
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
- append_open_io_if_needed(a_class)
56
- the_object = a_class.new
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(a_class)
115
- a_class.send(:prepend, OpenIo) unless a_class.include?(OpenIo)
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 = "ruby #{self.class.dasherize(name)} <(#{readers.join(' ')}) >(#{writers.join(' ')})"
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
@@ -1,3 +1,3 @@
1
1
  module DeadlySerious
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  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.1
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-19 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler