class IBM::Cloud::SDK::VPC::INSTANCE::Action

A base class that wraps the action response.

Attributes

data[RW]

The HTTP response object.

response[RW]

The HTTP response object.

Public Class Methods

new(response) click to toggle source
# File lib/ibm/cloud/sdk/vpc/instance/actions.rb, line 49
def initialize(response)
  @response = response
  @data = response.json
  @keys = %i[type force created_at]
  @deprecated = %i[completed_at started_at status id href]

  clear_deprecated
  add_inst_vars(@keys)
end

Public Instance Methods

created_at() click to toggle source

Return the DateTime the action was created. @return [DateTime]

# File lib/ibm/cloud/sdk/vpc/instance/actions.rb, line 61
def created_at
  return DateTime.parse(@created_at) if @created_at

  @created_at
end

Private Instance Methods

add_inst_vars(keys) click to toggle source

Iterate through an array of symbols. Set the instance variable and attr_accessor for each.

# File lib/ibm/cloud/sdk/vpc/instance/actions.rb, line 76
def add_inst_vars(keys)
  keys.each do |k|
    instance_variable_set "@#{k}", @data[k]
    self.class.attr_accessor k unless respond_to?(k)
  end
end
clear_deprecated() click to toggle source

Remove deprecated keys from hash.

# File lib/ibm/cloud/sdk/vpc/instance/actions.rb, line 84
def clear_deprecated
  @data.each do |k, _v|
    @data.delete(k) if @deprecated.include?(k)
  end
end