tailog 0.6.8 → 0.6.9

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: 1794b84df23a5eb4dcc558ad01c5d4af80300272
4
- data.tar.gz: 0f92833be4360d0da7e60ab3b909ca2ec6d140b9
3
+ metadata.gz: f16beba202bc6b12214c29111e8902b13d4d57f9
4
+ data.tar.gz: e9dff97596dfb7da548391f802943a498c944da7
5
5
  SHA512:
6
- metadata.gz: 6309d780432e92dfddcebd5878736b88898bcf8525e0f15f700e7230a741e6ce968f51afefbe37ce463827da2d86f0a2251d2ec4fba7e24d5cf6d718163f64f3
7
- data.tar.gz: 75bbe56d2a776238f00214b10de67e632b02d4e244800200070c78d31897fbe2f908494fa8338a9fd0625d6a15aecdf63bc95e47d7f3da331bc81820afe049fa
6
+ metadata.gz: 99b581a2eb9737d4433601b9c64d6e77f0c2fc213566cbf768bfc0680642a33ef9dfcf6f8908c4a323e3412e901f34819abf267a97207fefadaeb8233e6037b3
7
+ data.tar.gz: 48909e91421c2ae410385c893ceb1a0e7ab7a649560d2930edf1ced629fa9025692b53f18533cf0dba5c047bf4211b4a1efade72dee7482353064cefee783867
@@ -1,21 +1,13 @@
1
1
  <% begin %>
2
- <% Open3.popen3("bash -x -e") do |stdin, stdout, stderr, wait_thr| %>
3
- <% output = [] %>
4
- <% Thread.new do until (line = stdout.gets).nil? do output << [ :stdout, line ] end end %>
5
- <% Thread.new do until (line = stderr.gets).nil? do output << [ :stderr, line ] end end %>
6
-
7
- <% stdin.puts script %>
8
- <% stdin.puts "exit" %>
9
- <% wait_thr.join %>
10
-
11
- <% output.each do |key, line| %>
12
- <% if key == :stdout %>
13
- <p><%= h line %></p>
14
- <% elsif line =~ /^\+ (.*)/ %>
15
- <p class="text-info">$ <%= h $1 %></p>
16
- <% else %>
17
- <p class="text-danger"><%= h line %></p>
18
- <% end %>
2
+ <% output = Bash.evaluate_string script %>
3
+ <% output.each do |key, line| %>
4
+ <% case key
5
+ when :stdin %>
6
+ <p class="text-info"><%= h line %></p>
7
+ <% when :stdout %>
8
+ <p><%= h line %></p>
9
+ <% when :stderr %>
10
+ <p class="text-danger"><%= h line %></p>
19
11
  <% end %>
20
12
  <% end %>
21
13
  <% rescue => error %>
@@ -1,28 +1,15 @@
1
1
  <% begin %>
2
- <% irb = IRB::Irb.new nil, StringInputMethod.new(script + "\nexit\n") %>
3
- <% IRB.conf[:MAIN_CONTEXT] = irb.context %>
4
- <% IRB.conf[:OUTPUT] = [] %>
5
-
6
- <% begin %>
7
- <% irb.eval_input %>
8
- <% IRB.Output.each do |key, line| %>
9
- <% case key
10
- when :stdin %>
11
- <p class="text-info"><%= h line %></p>
12
- <% when :stdout %>
13
- <p><%= h line %></p>
14
- <% when :stderr %>
15
- <p class="text-danger"><%= h line %></p>
16
- <% end %>
17
- <% end %>
18
- <% rescue => error %>
19
- <p class="text-danger"><%= h error.class %>: <%= h error.message %></p>
20
- <% error.backtrace.each do |backtrace| %>
21
- <p class="text-danger"> <%= h backtrace %></p>
2
+ <% output = IRB.evaluate_string script %>
3
+ <% output.each do |key, line| %>
4
+ <% case key
5
+ when :stdin %>
6
+ <p class="text-info"><%= h line %></p>
7
+ <% when :stdout %>
8
+ <p><%= h line %></p>
9
+ <% when :stderr %>
10
+ <p class="text-danger"><%= h line %></p>
22
11
  <% end %>
23
12
  <% end %>
24
-
25
13
  <% rescue => error %>
26
14
  <%= erb :error, locals: { error: error }, layout: false %>
27
15
  <% end %>
28
-
@@ -0,0 +1,23 @@
1
+ module Bash
2
+ def self.evaluate_string script
3
+ output = []
4
+
5
+ Open3.popen3("bash -x -e") do |stdin, stdout, stderr, wait_thr|
6
+ Thread.new do until (line = stdout.gets).nil? do output << [ :stdout, line ] end end
7
+ Thread.new do until (line = stderr.gets).nil? do output << [ :stderr, line ] end end
8
+
9
+ stdin.puts script
10
+ stdin.puts "exit"
11
+
12
+ wait_thr.join
13
+ end
14
+
15
+ output.map do |key, line|
16
+ if key == :stderr && line =~ /^\+ (.*)/
17
+ [:stdin, line]
18
+ else
19
+ [key, line]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,8 +1,6 @@
1
1
  require 'irb'
2
2
 
3
3
  IRB.init_config nil
4
- IRB.conf[:PROMPT_MODE] = :DEFAULT
5
- IRB.conf[:VERBOSE] = false
6
4
 
7
5
  class << IRB
8
6
  def Output
@@ -14,9 +12,13 @@ class << IRB
14
12
  conf[:VERBOSE] = false
15
13
  conf[:OUTPUT] = []
16
14
 
17
- irb = Irb.new nil, StringInputMethod.new(string + "\n")
15
+ irb = IRB::Irb.new nil, StringInputMethod.new(string + "\nexit\n")
18
16
  conf[:MAIN_CONTEXT] = irb.context
19
17
  irb.eval_input
18
+
19
+ result = conf[:OUTPUT]
20
+ conf[:OUTPUT] = nil
21
+ result
20
22
  end
21
23
 
22
24
  alias_method :raw_irb_exit, :irb_exit
@@ -1,3 +1,3 @@
1
1
  module Tailog
2
- VERSION = "0.6.8"
2
+ VERSION = "0.6.9"
3
3
  end
data/lib/tailog.rb CHANGED
@@ -4,6 +4,7 @@ require 'tailog/request_id'
4
4
  require 'tailog/watch_methods'
5
5
  require 'tailog/ext/file'
6
6
  require 'tailog/ext/integer'
7
+ require 'tailog/ext/bash'
7
8
  require 'tailog/ext/irb'
8
9
 
9
10
  require 'sinatra/base'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tailog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - bbtfr
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -95,6 +95,7 @@ files:
95
95
  - bin/setup
96
96
  - lib/tailog.rb
97
97
  - lib/tailog/eval.rb
98
+ - lib/tailog/ext/bash.rb
98
99
  - lib/tailog/ext/file.rb
99
100
  - lib/tailog/ext/integer.rb
100
101
  - lib/tailog/ext/irb.rb