lib/rye.rb in rye-0.8.19 vs lib/rye.rb in rye-0.9.0
- old
+ new
@@ -40,11 +40,11 @@
# http://paste.lisp.org/display/6912
#++
module Rye
extend self
- VERSION = "0.8.19".freeze unless defined?(VERSION)
+ VERSION = "0.9.0".freeze unless defined?(VERSION)
@@sysinfo = nil
@@agent_env = Hash.new # holds ssh-agent env vars
@@mutex = Mutex.new # for synchronizing threads
@@ -66,22 +66,22 @@
class NotConnected < RyeError; end
class CommandNotFound < RyeError; end
class NoPty < RyeError
def message; "Could not obtain pty (i.e. an interactive ssh session)"; end
end
- class CommandError < RyeError
+ class Err < RyeError
attr_reader :rap
# * +rap+ a Rye::Rap object
def initialize(rap)
@rap = rap
end
def message
- "%s (code: %s)" % [@rap.stderr.join($/), @rap.exit_code]
+ "%s (cmd: %s; status: %s)" % [@rap.stderr.join($/), @rap.cmd, @rap.exit_status]
end
def stderr; @rap.stderr if @rap; end
def stdout; @rap.stdout if @rap; end
- def exit_code; @rap.exit_code if @rap; end
+ def exit_status; @rap.exit_status if @rap; end
end
# Reload Rye dynamically. Useful with irb.
# NOTE: does not reload rye.rb.
def reload
@@ -221,11 +221,11 @@
tf.delete
# Create the response object
rap = Rye::Rap.new(self)
rap.add_stdout(stdout || '')
rap.add_stderr(stderr || '')
- rap.add_exit_code($?)
+ rap.add_exit_status($?)
rap
end
# Creates a string from +cmd+ and +args+. If +safe+ is true
# it will send them through Escape.shell_command otherwise
@@ -255,9 +255,36 @@
chars = ("a".."z").to_a + ("0".."9").to_a
chars.delete_if { |v| %w(i l o 1 0).member?(v) } if safe
str = ""
1.upto(len) { |i| str << chars[rand(chars.size-1)] }
str
+ end
+
+ class Tpl
+ attr_reader :src, :result, :basename
+ def initialize(src, basename='rye-template')
+ @basename = basename
+ src = src.to_s
+ @src, @template = src, ERB.new(src)
+ end
+ def path
+ if @tf.nil?
+ @tf = Tempfile.new basename
+ @tf.write @result
+ @tf.close
+ end
+ @tf.path
+ end
+ def delete
+ File.delete(@tf.path) if File.exists?(@tf.path)
+ end
+ def result!(binding)
+ @result = result(binding)
+ end
+ def result(binding)
+ @template.result(binding)
+ end
+ def to_s() src end
end
private
Rye.reload
\ No newline at end of file