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.



26
27
28
29
30
31
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 26

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)


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

def value
  @value
end

Instance Method Details

#[](v) ⇒ Object



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

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)


38
39
40
41
42
43
44
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 38

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



51
52
53
# File 'lib/vagrant-vmware-desktop/helper/vagrant_utility.rb', line 51

def success?
  value[:success]
end