Class: HashiCorp::VagrantVMwareDesktop::Helper::VagrantUtility::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-vmware-desktop/helper/vagrant_utility.rb

Overview

Response wrapper class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Response

Returns a new instance of Response.



23
24
25
26
27
28
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 23

def initialize(value)
  if !value.is_a?(Hash)
    raise TypeError.new("Expecting value of `Hash` type but received `#{value.class}`")
  end
  @value = value
end

Instance Attribute Details

#valueHash (readonly)

Raw value being wrapped

Returns:

  • (Hash)


21
22
23
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 21

def value
  @value
end

Instance Method Details

#[](v) ⇒ Object



43
44
45
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 43

def [](v)
  value[v]
end

#get(*args) ⇒ Object

Provides Hash#dig functionality but will raise an invalid response exception if given path raises an error.

Returns:

  • (Object)


35
36
37
38
39
40
41
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 35

def get(*args)
  begin
    value.dig(*args)
  rescue => err
    raise Errors::DriverAPIInvalidResponse
  end
end

#success?TrueClass, FalseClass

Returns response is success.

Returns:

  • (TrueClass, FalseClass)

    response is success



48
49
50
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 48

def success?
  value[:success]
end