lib/vos/box.rb in vos-0.1.0 vs lib/vos/box.rb in vos-0.1.1

- old
+ new

@@ -2,26 +2,37 @@ class Box include Shell, Marks, Vfs attr_accessor :options - def initialize options = {} - @options = options - options[:host] ||= 'localhost' + def initialize *args + first = args.first + if args.empty? + @driver = Drivers::Local.new + elsif first.is_a?(String) or first.is_a?(Symbol) or first.is_a?(Hash) and (args.size <= 2) + if first.is_a? Hash + options = first + options[:host] ||= 'localhost' + else + options = args[1] || {} + raise 'invalid arguments' unless options.is_a?(Hash) + options[:host] = first.to_s + end + + @driver = options[:host] == 'localhost' ? Drivers::Local.new(options) : Drivers::Ssh.new(options) + elsif args.size == 1 + @driver = first + else + raise 'invalid arguments' + end end # # driver # - def driver - unless @driver - klass = options[:host] == 'localhost' ? Drivers::Local : Drivers::Ssh - @driver = klass.new options - end - @driver - end + attr_reader :driver def open &block driver.open &block end def close @@ -31,15 +42,16 @@ # # Micelaneous # def inspect - host = options[:host] - if host == 'localhost' - '' - else - host - end + driver.to_s + # host = options[:host] + # if host == 'localhost' + # '' + # else + # host + # end end alias_method :to_s, :inspect end end \ No newline at end of file