shr 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/shr/command.rb CHANGED
@@ -31,11 +31,17 @@ module Shr
31
31
  end
32
32
 
33
33
  # xxx
34
- def run(environment)
35
- pid = spawn(self.to_s, environment)
34
+ def run(environment, command_out)
35
+ io_r, io_w = IO.pipe
36
+ options = { :out => io_w }
37
+ options[:in] = command_out if command_out
38
+ options.merge!(environment)
39
+
40
+ pid = spawn(self.to_s, options)
36
41
  watcher = Process.detach(pid)
37
- environment[:out].close if environment[:out].kind_of?(IO)
38
- watcher
42
+ io_w.close
43
+
44
+ [io_r, watcher]
39
45
  end
40
46
 
41
47
  # xxx
data/lib/shr/shell.rb CHANGED
@@ -5,7 +5,7 @@ module Shr
5
5
  class Shell
6
6
 
7
7
  def initialize
8
- @promise = []
8
+ @commands = []
9
9
  end
10
10
 
11
11
  def method_missing(name, *args)
@@ -25,7 +25,7 @@ module Shr
25
25
  end
26
26
 
27
27
  def inspect
28
- command_line = @promise.join(' | ').strip
28
+ command_line = @commands.join(' | ').strip
29
29
  force
30
30
  res = "#<Shr::Shell>"
31
31
  res << "<:command => #{command_line}>" if command_line.size > 0
@@ -68,34 +68,24 @@ module Shr
68
68
  end
69
69
 
70
70
  def delay(command)
71
- @promise << command
71
+ @commands << command
72
72
  end
73
73
 
74
- # xxx
75
74
  def force(args={})
76
- return if @promise.empty?
75
+ return if @commands.empty?
77
76
 
78
- @promise.each do |promise|
79
- io_r, io_w = IO.pipe
80
- environment = { :out => io_w }
81
- environment[:in] = @command_out if @command_out
82
- environment.merge!(args)
83
-
84
- watcher = promise.run(environment)
85
-
86
- @command_out = io_r
87
- @wait_thread = watcher
77
+ @commands.each do |command|
78
+ @command_out, @wait_thread = command.run(args, @command_out)
88
79
  end
89
-
90
- @promise.clear
80
+ @wait_thread.join
81
+ @commands.clear
91
82
  end
92
83
 
93
- # xxx
94
84
  def force!
95
- return if @promise.empty?
85
+ return if @commands.empty?
96
86
 
97
- @promise[-1].run!
98
- @promise.clear
87
+ @commands[-1].run!
88
+ @commands.clear
99
89
  end
100
90
  end
101
91
  end
data/lib/shr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Shr
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -28,7 +28,8 @@ module Shr
28
28
 
29
29
  describe '#to_s' do
30
30
  it 'returns the command and parsed options' do
31
- cmd.to_s.should eq('ls -l -t -r')
31
+ cmd.to_s.should eq('ls -l -t -r') unless OS.windows?
32
+ cmd.to_s.should eq('ls /l /t /r') if OS.windows?
32
33
  end
33
34
  end
34
35
 
@@ -84,7 +84,7 @@ module Shr
84
84
  it 'redirecs result of command to file' do
85
85
  tempfile = Tempfile.new('temp')
86
86
  sh.pwd.redirect_to(tempfile.path)
87
- sh.cat(tempfile.path).to_s.should eq(`pwd`)
87
+ sh.cat.redirect_from(tempfile.path).to_s.should eq(`pwd`)
88
88
  tempfile.close!
89
89
  end
90
90
  end
@@ -67,7 +67,7 @@ module Shr
67
67
  it 'redirecs result of command to file' do
68
68
  tempfile = Tempfile.new('temp')
69
69
  sh.chdir.redirect_to(tempfile.path)
70
- sh.type(tempfile.path.gsub('/', '\\')).to_s.should eq(`chdir`)
70
+ sh.more.redirect_from(tempfile.path).to_s.should eq(`chdir`)
71
71
  tempfile.close!
72
72
  end
73
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-20 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: os
@@ -35,7 +35,6 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - .gitignore
38
- - .swp
39
38
  - Gemfile
40
39
  - Guardfile
41
40
  - LICENSE.md
data/.swp DELETED
Binary file