Class: Vos::Box

Inherits:
Object
  • Object
show all
Includes:
Marks, Shell, Vfs
Defined in:
lib/vos/box.rb,
lib/vos/box/vfs.rb,
lib/vos/box/marks.rb,
lib/vos/box/shell.rb

Defined Under Namespace

Modules: Marks, Shell, Vfs

Instance Attribute Summary collapse

Attributes included from Shell

#env

Instance Method Summary collapse

Methods included from Shell

#bash, #bash_without_path, #default_env, #exec, #home, #wrap_cmd

Methods included from Marks

#clear_marks, #has_mark?, #mark

Methods included from Vfs

#open_fs, #to_dir, #to_entry, #to_file

Constructor Details

#initialize(*args) ⇒ Box

Returns a new instance of Box.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vos/box.rb', line 7

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

Instance Attribute Details

#driverObject (readonly)

driver



33
34
35
# File 'lib/vos/box.rb', line 33

def driver
  @driver
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/vos/box.rb', line 5

def options
  @options
end

Instance Method Details

#closeObject



38
39
40
# File 'lib/vos/box.rb', line 38

def close
  driver.close
end

#inspectObject Also known as: to_s

Micelaneous



46
47
48
49
50
51
52
53
54
# File 'lib/vos/box.rb', line 46

def inspect
  driver.to_s
  # host = options[:host]
  # if host == 'localhost'
  #   ''
  # else
  #   host
  # end
end

#open(&block) ⇒ Object



35
36
37
# File 'lib/vos/box.rb', line 35

def open &block
  driver.open &block
end