proclib 0.1.0 → 0.1.1

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: b8a7d4e4a70ff96e2309807bffc296bb93d9aa67
4
- data.tar.gz: 4c09847012dfc3010071e7d589ab6802786726fe
3
+ metadata.gz: 0f14da2636c7920354164801ec23b79a257e0bf1
4
+ data.tar.gz: 804b5af1d78d5f3295688362451ca40ca719213e
5
5
  SHA512:
6
- metadata.gz: cead6a0fffa9ee03ae07ab6ea2c0dfd368171497e4b30f5b31d7c12bfedfde362d76bcd2bf1d6788aba12dbf05369a196ab235783507a7f9d290239f4782b1a1
7
- data.tar.gz: 9b4385413c690e8ef80484b6d20fe986f2d23f97a1cba6a9f3157ce203db427b78620a233dffeb3ab63cdbc2d35ea80b1b4d989686a0fd9871c1574e266f3e95
6
+ metadata.gz: 7df0c94025f7aac0fc1cd90631799b49978c6aad6ab0e03be49c944e2a3eeeac28ece0c7ded5ed95218da6922fc37ce711102fa511bfab4cfe33676c0adadaf7
7
+ data.tar.gz: 8f8b399172a311691292f17dd0e9a3f9bf2ffc74bdf162bbd54bbe46b5cb9b37703c0d49b0844bf1e42637eea3a865b087b5c36767665bd581a34d8d3944f666
data/examples/main.rb CHANGED
@@ -16,6 +16,12 @@ _, stdout, _ = Proclib.run("ls /tmp/", capture_output: true)
16
16
  puts "Files in /tmp"
17
17
  puts stdout.join
18
18
 
19
- cmd = "seq 1 10 | while read n; do echo $n; sleep 0.5; done"
19
+ cmd = "seq 1 5 | while read n; do echo $n; sleep 0.5; done"
20
20
 
21
- Proclib.run({tmp: cmd, home: cmd}, log_to_console: true)
21
+ Proclib.run({one: cmd, two: cmd}, log_to_console: true)
22
+
23
+ output_callback = -> (line, tag, pipe_name) {
24
+ STDOUT.printf("%s:%s:%s", tag, pipe_name, line)
25
+ }
26
+
27
+ Proclib.run(cmd, tag: :count_things, on_output: output_callback)
data/lib/proclib.rb CHANGED
@@ -10,7 +10,12 @@ require 'proclib/executor'
10
10
 
11
11
  module Proclib
12
12
  module Methods
13
- def run(cmd, tag: nil, log_to_console: false, capture_output: true)
13
+ def run(cmd,
14
+ tag: nil,
15
+ log_to_console: false,
16
+ capture_output: true,
17
+ on_output: nil)
18
+
14
19
  runnable = if cmd.kind_of? String
15
20
  Process.new(cmd, tag: tag || cmd[0..20])
16
21
  elsif cmd.kind_of?(Hash)
@@ -21,9 +26,16 @@ module Proclib
21
26
  "Expected String or Hash"
22
27
  end
23
28
 
29
+ unless on_output.nil? || on_output.kind_of?(Proc) || on_ouptut.kind_of?(Lambda)
30
+ raise ArgumentError, "Expected :on_output to be a proc or lambda if given"
31
+ end
32
+
24
33
  executor = Executor.new(runnable,
25
34
  log_to_console: log_to_console,
35
+ on_output: on_output,
26
36
  cache_output: capture_output)
37
+
38
+
27
39
  executor.run_sync
28
40
  end
29
41
  end
@@ -40,6 +40,13 @@ module Proclib
40
40
  def configure_output
41
41
  channel.on(:output) {|e| console_logger << e.data } if opts[:log_to_console]
42
42
  channel.on(:output) {|e| output_cache << e.data} if opts[:cache_output]
43
+
44
+ if opts[:on_output]
45
+ channel.on(:output) do |e|
46
+ msg = e.data
47
+ opts[:on_output].call(msg.line, msg.process_tag, msg.pipe_name)
48
+ end
49
+ end
43
50
  end
44
51
 
45
52
  def output_cache
@@ -1,3 +1,3 @@
1
1
  module Proclib
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proclib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Forrest