Class: Aws::Structure Private

Inherits:
Struct
  • Object
show all
Defined in:
lib/aws-sdk-core/structure.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) ⇒ Structure

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Structure.



9
10
11
12
13
# File 'lib/aws-sdk-core/structure.rb', line 9

def initialize(values = {})
  values.each do |k, v|
    self[k] = v
  end
end

Class Method Details

.new(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
64
65
# File 'lib/aws-sdk-core/structure.rb', line 57

def new(*args)
  if args == ['AwsEmptyStructure']
    super
  elsif args.empty? || args.first == []
    EmptyStructure
  else
    super(*args)
  end
end

Instance Method Details

#empty?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns ‘true` if all of the member values are `nil`.

Returns:

  • (Boolean)

    Returns ‘true` if all of the member values are `nil`.



22
23
24
# File 'lib/aws-sdk-core/structure.rb', line 22

def empty?
  values.compact == []
end

#key?(member_name) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns ‘true` if this structure has a value set for the given member.

Returns:

  • (Boolean)

    Returns ‘true` if this structure has a value set for the given member.



17
18
19
# File 'lib/aws-sdk-core/structure.rb', line 17

def key?(member_name)
  !self[member_name].nil?
end

#orig_to_hObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



6
# File 'lib/aws-sdk-core/structure.rb', line 6

alias orig_to_h to_h

#to_h(obj = self) ⇒ Hash Also known as: to_hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Deeply converts the Structure into a hash. Structure members that are ‘nil` are omitted from the resultant hash.

You can call #orig_to_h to get vanilla #to_h behavior as defined in stdlib Struct.

Returns:

  • (Hash)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/aws-sdk-core/structure.rb', line 33

def to_h(obj = self)
  case obj
  when Struct
    obj.members.each.with_object({}) do |member, hash|
      value = obj[member]
      hash[member] = to_hash(value) unless value.nil?
    end
  when Hash
    obj.each.with_object({}) do |(key, value), hash|
      hash[key] = to_hash(value)
    end
  when Array
    obj.collect { |value| to_hash(value) }
  else
    obj
  end
end