rush 0.4.1 → 0.4.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.
- data/Rakefile +1 -2
- data/lib/rush/file.rb +8 -0
- data/lib/rush/local.rb +20 -3
- data/lib/rush/remote.rb +4 -0
- data/spec/file_spec.rb +4 -0
- data/spec/local_spec.rb +12 -0
- data/spec/remote_spec.rb +5 -0
- metadata +2 -12
data/Rakefile
CHANGED
@@ -31,7 +31,7 @@ require 'rake/rdoctask'
|
|
31
31
|
require 'fileutils'
|
32
32
|
include FileUtils
|
33
33
|
|
34
|
-
version = "0.4.
|
34
|
+
version = "0.4.2"
|
35
35
|
name = "rush"
|
36
36
|
|
37
37
|
spec = Gem::Specification.new do |s|
|
@@ -46,7 +46,6 @@ spec = Gem::Specification.new do |s|
|
|
46
46
|
s.rubyforge_project = "ruby-shell"
|
47
47
|
|
48
48
|
s.add_dependency 'mongrel'
|
49
|
-
s.add_dependency 'rspec'
|
50
49
|
s.add_dependency 'session'
|
51
50
|
|
52
51
|
s.platform = Gem::Platform::RUBY
|
data/lib/rush/file.rb
CHANGED
@@ -22,6 +22,8 @@ class Rush::File < Rush::Entry
|
|
22
22
|
connection.file_contents(full_path)
|
23
23
|
end
|
24
24
|
|
25
|
+
alias :read :contents
|
26
|
+
|
25
27
|
# Write to the file, overwriting whatever was already in it.
|
26
28
|
#
|
27
29
|
# Example: file.write "hello, world\n"
|
@@ -29,6 +31,12 @@ class Rush::File < Rush::Entry
|
|
29
31
|
connection.write_file(full_path, new_contents)
|
30
32
|
end
|
31
33
|
|
34
|
+
# Append new contents to the end of the file, keeping what was in it.
|
35
|
+
def append(contents)
|
36
|
+
connection.append_to_file(full_path, contents)
|
37
|
+
end
|
38
|
+
alias_method :<<, :append
|
39
|
+
|
32
40
|
# Return an array of lines from the file, similar to stdlib's File#readlines.
|
33
41
|
def lines
|
34
42
|
contents.split("\n")
|
data/lib/rush/local.rb
CHANGED
@@ -21,6 +21,14 @@ class Rush::Connection::Local
|
|
21
21
|
true
|
22
22
|
end
|
23
23
|
|
24
|
+
# Append contents to a file
|
25
|
+
def append_to_file(full_path, contents)
|
26
|
+
::File.open(full_path, 'a') do |f|
|
27
|
+
f.write contents
|
28
|
+
end
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
24
32
|
# Read raw bytes from a file.
|
25
33
|
def file_contents(full_path)
|
26
34
|
::File.read(full_path)
|
@@ -310,26 +318,34 @@ class Rush::Connection::Local
|
|
310
318
|
end
|
311
319
|
|
312
320
|
def bash_background(command, user)
|
313
|
-
inpipe, outpipe = IO.pipe
|
314
|
-
|
315
321
|
pid = fork do
|
322
|
+
inpipe, outpipe = IO.pipe
|
323
|
+
|
316
324
|
outpipe.write command
|
317
325
|
outpipe.close
|
318
326
|
STDIN.reopen(inpipe)
|
319
327
|
|
328
|
+
close_all_descriptors([inpipe.to_i])
|
329
|
+
|
320
330
|
if user and user != ''
|
321
331
|
exec "cd /; sudo -H -u #{user} bash"
|
322
332
|
else
|
323
333
|
exec "bash"
|
324
334
|
end
|
325
335
|
end
|
326
|
-
outpipe.close
|
327
336
|
|
328
337
|
Process::detach pid
|
329
338
|
|
330
339
|
pid
|
331
340
|
end
|
332
341
|
|
342
|
+
def close_all_descriptors(keep_open = [])
|
343
|
+
3.upto(256) do |fd|
|
344
|
+
next if keep_open.include?(fd)
|
345
|
+
IO::new(fd).close rescue nil
|
346
|
+
end
|
347
|
+
end
|
348
|
+
|
333
349
|
####################################
|
334
350
|
|
335
351
|
# Raised when the action passed in by RushServer is not known.
|
@@ -342,6 +358,7 @@ class Rush::Connection::Local
|
|
342
358
|
def receive(params)
|
343
359
|
case params[:action]
|
344
360
|
when 'write_file' then write_file(params[:full_path], params[:payload])
|
361
|
+
when 'append_to_file' then append_to_file(params[:full_path], params[:payload])
|
345
362
|
when 'file_contents' then file_contents(params[:full_path])
|
346
363
|
when 'destroy' then destroy(params[:full_path])
|
347
364
|
when 'purge' then purge(params[:full_path])
|
data/lib/rush/remote.rb
CHANGED
@@ -18,6 +18,10 @@ class Rush::Connection::Remote
|
|
18
18
|
transmit(:action => 'write_file', :full_path => full_path, :payload => contents)
|
19
19
|
end
|
20
20
|
|
21
|
+
def append_to_file(full_path, contents)
|
22
|
+
transmit(:action => 'append_to_file', :full_path => full_path, :payload => contents)
|
23
|
+
end
|
24
|
+
|
21
25
|
def file_contents(full_path)
|
22
26
|
transmit(:action => 'file_contents', :full_path => full_path)
|
23
27
|
end
|
data/spec/file_spec.rb
CHANGED
@@ -39,6 +39,10 @@ describe Rush::File do
|
|
39
39
|
@file.contents.should == @contents
|
40
40
|
end
|
41
41
|
|
42
|
+
it "read is an alias for contents" do
|
43
|
+
@file.read.should == @contents
|
44
|
+
end
|
45
|
+
|
42
46
|
it "can write new contents" do
|
43
47
|
@file.write('write test')
|
44
48
|
@file.contents.should == 'write test'
|
data/spec/local_spec.rb
CHANGED
@@ -17,6 +17,11 @@ describe Rush::Connection::Local do
|
|
17
17
|
@con.receive(:action => 'write_file', :full_path => 'file', :payload => 'contents')
|
18
18
|
end
|
19
19
|
|
20
|
+
it "receive -> append_to_file(file, contents)" do
|
21
|
+
@con.should_receive(:append_to_file).with('file', 'contents')
|
22
|
+
@con.receive(:action => 'append_to_file', :full_path => 'file', :payload => 'contents')
|
23
|
+
end
|
24
|
+
|
20
25
|
it "receive -> file_contents(file)" do
|
21
26
|
@con.should_receive(:file_contents).with('file').and_return('the contents')
|
22
27
|
@con.receive(:action => 'file_contents', :full_path => 'file').should == 'the contents'
|
@@ -116,6 +121,13 @@ describe Rush::Connection::Local do
|
|
116
121
|
File.read(fname).should == data
|
117
122
|
end
|
118
123
|
|
124
|
+
it "append_to_file appends contents to a file" do
|
125
|
+
fname = "#{@sandbox_dir}/a_file"
|
126
|
+
system "echo line1 > #{fname}"
|
127
|
+
@con.append_to_file(fname, 'line2')
|
128
|
+
File.read(fname).should == "line1\nline2"
|
129
|
+
end
|
130
|
+
|
119
131
|
it "file_contents reads a file's contents" do
|
120
132
|
fname = "#{@sandbox_dir}/a_file"
|
121
133
|
system "echo stuff > #{fname}"
|
data/spec/remote_spec.rb
CHANGED
@@ -17,6 +17,11 @@ describe Rush::Connection::Local do
|
|
17
17
|
@con.write_file('file', 'contents')
|
18
18
|
end
|
19
19
|
|
20
|
+
it "transmits append_to_file" do
|
21
|
+
@con.should_receive(:transmit).with(:action => 'append_to_file', :full_path => 'file', :payload => 'contents')
|
22
|
+
@con.append_to_file('file', 'contents')
|
23
|
+
end
|
24
|
+
|
20
25
|
it "transmits file_contents" do
|
21
26
|
@con.should_receive(:transmit).with(:action => 'file_contents', :full_path => 'file').and_return('contents')
|
22
27
|
@con.file_contents('file').should == 'contents'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rush
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Wiggins
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-22 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -22,16 +22,6 @@ dependencies:
|
|
22
22
|
- !ruby/object:Gem::Version
|
23
23
|
version: "0"
|
24
24
|
version:
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: rspec
|
27
|
-
type: :runtime
|
28
|
-
version_requirement:
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: "0"
|
34
|
-
version:
|
35
25
|
- !ruby/object:Gem::Dependency
|
36
26
|
name: session
|
37
27
|
type: :runtime
|