Class: Mock

Inherits:
String
  • Object
show all
Defined in:
lib/Mock.rb

Overview

A class to replace all vmware data structures with random text if vmware lib not available

Instance Method Summary collapse

Constructor Details

#initializeMock

initializes self with a random string



6
7
8
9
10
11
12
13
14
# File 'lib/Mock.rb', line 6

def initialize
  # methods that just need to be there to show the task buttons
  @methods = [:powerOnVM_Task,:shutdownGuest,:powerOffVM,:markAsVirtualMachine,:markAsTemplate,:suspendVM_Task,:resetVM_Task,:rebootGuest,:migrateVM_Task]
  res = ''
  -3.upto(rand 8) do
    res << (65 + rand(57))
  end
  super res
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

fake if a vmware data structure should respond to this method



27
28
29
30
# File 'lib/Mock.rb', line 27

def method_missing sym, *args
  return if @methods.include? sym.to_sym
  super
end

Instance Method Details

#[](i = nil) ⇒ Object Also known as: task_manager, recent_tasks

returns a new instance of it’s own class



16
17
18
# File 'lib/Mock.rb', line 16

def [] i=nil
  self.class.new
end

#respond_to?(sym) ⇒ Boolean

expand the list of methods this class responds to

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/Mock.rb', line 22

def respond_to? sym
  return true if @methods.include? sym.to_sym
  super
end

#soap_classObject

returns something VcData interprets as device



32
33
34
# File 'lib/Mock.rb', line 32

def soap_class
  'VirtualDisk'
end