lib/rye/box.rb in rye-0.7.1 vs lib/rye/box.rb in rye-0.7.2
- old
+ new
@@ -30,11 +30,12 @@
include Rye::Cmd
def host; @rye_host; end
def opts; @rye_opts; end
def safe; @rye_safe; end
-
+ def user; (@rye_opts || {})[:user]; end
+
def host=(val); @rye_host = val; end
def opts=(val); @rye_opts = val; end
def safe=(val); @rye_safe = val; end
# The most recent value from Box.cd or Box.[]
@@ -135,18 +136,30 @@
# rbox.pwd # => /home/rye ($ pwd )
# rbox['/usr/bin'].pwd # => /usr/bin ($ cd /usr/bin && pwd)
# rbox.pwd # => /usr/bin ($ cd /usr/bin && pwd)
#
def [](key=nil)
- @rye_current_working_directory = key
+ if key.nil? || key.index('/') == 0
+ @rye_current_working_directory = key
+ else
+ # Append to non-absolute paths
+ newpath = File.join(@rye_current_working_directory, key)
+ @rye_current_working_directory = File.expand_path(newpath)
+ end
self
end
# Like [] except it returns an empty Rye::Rap object to mimick
# a regular command method. Call with nil key (or no arg) to
# reset.
def cd(key=nil)
- @rye_current_working_directory = key
+ if key.nil? || key.index('/') == 0
+ @rye_current_working_directory = key
+ else
+ # Append to non-absolute paths
+ newpath = File.join(@rye_current_working_directory, key)
+ @rye_current_working_directory = File.expand_path(newpath)
+ end
ret = Rye::Rap.new(self)
end
# Change the current umask (sort of -- works the same way as cd)
# The default umask is 0022
@@ -306,13 +319,10 @@
(@rye_current_environment_variables ||= {})[n] = v
self
end
alias :add_env :setenv # deprecated?
- # The name of the user that opened the SSH connection
- def user; (@rye_opts || {})[:user]; end
-
# See Rye.keys
def keys; Rye.keys; end
# Returns +user@rye_host+
def to_s; '%s@rye_%s' % [user, @rye_host]; end
@@ -471,12 +481,15 @@
prep_args(*args).join(' ')
end
# Supply a block to be called before every command. It's called
- # with three arguments: command name, an Array of arguments, user name
- #
+ # with three arguments: command name, an Array of arguments, user name, hostname
+ # e.g.
+ # rbox.pre_command_hook do |cmd,args,user,host|
+ # ...
+ # end
def pre_command_hook(&block)
@rye_pre_command_hook = block if block
@rye_pre_command_hook
end
@@ -589,10 +602,10 @@
info "COMMAND: #{cmd_clean}"
debug "Executing: %s" % cmd_clean
if @rye_pre_command_hook.is_a?(Proc)
- @rye_pre_command_hook.call(cmd, args, opts[:user])
+ @rye_pre_command_hook.call(cmd, args, user, host)
end
## NOTE: Do not raise a CommandNotFound exception in this method.
# We want it to be possible to define methods to a single instance
# of Rye::Box. i.e. def rbox.rm()...