Class: Aws::Resources::Resource

Inherits:
Object
  • Object
show all
Extended by:
OperationMethods
Defined in:
aws-sdk-resources/lib/aws-sdk-resources/resource.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OperationMethods

add_batch_operation, add_operation, batch_operation, batch_operation_names, batch_operations, operation, operation_names, operations

Constructor Details

#initialize(*identifiers, options = {}) ⇒ Resource

Returns a new instance of Resource.

Parameters:

  • options (Hash) (defaults to: {})

    Options except :data and identifier options are used to construct a Client unless :client is given.

Options Hash (options):


11
12
13
14
15
16
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 11

def initialize(*args)
  options = args.last.is_a?(Hash) ? args.pop.dup : {}
  @identifiers = extract_identifiers(args, options)
  @data = options.delete(:data)
  @client = extract_client(options)
end

Class Attribute Details

.client_classClass<Client>?

Returns When constructing a resource, the client will default to an instance of the this class.

Returns:

  • (Class<Client>, nil)

    When constructing a resource, the client will default to an instance of the this class.


92
93
94
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 92

def client_class
  @client_class
end

.load_operationOperations::LoadOperation?

Returns:


95
96
97
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 95

def load_operation
  @load_operation
end

.resource_nameString?

Returns The resource name.

Returns:

  • (String, nil)

    The resource name.


87
88
89
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 87

def resource_name
  @resource_name
end

Instance Attribute Details

#clientClient (readonly)

Marked private to prevent double documentation

Returns:


20
21
22
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 20

def client
  @client
end

#identifiersHash<Symbol,String> (readonly)

Marked private to prevent double documentation

Returns:

  • (Hash<Symbol,String>)

24
25
26
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 24

def identifiers
  @identifiers
end

Class Method Details

.add_data_attribute(name) ⇒ void

This method returns an undefined value.

Registers a data attribute. This defines a simple getter for the attribute which will access #data, loading the resource if necessary.

Parameters:

  • name (Symbol)

117
118
119
120
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 117

def add_data_attribute(name)
  safe_define_method(name) { data[name] }
  @data_attributes << name
end

.add_identifier(name) ⇒ void

This method returns an undefined value.

Parameters:

  • name (Symbol)

106
107
108
109
110
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 106

def add_identifier(name)
  name = name.to_sym
  safe_define_method(name) { @identifiers[name] }
  @identifiers << name
end

.data_attributesArray<Symbol>

Returns an array of symbolized data attribute names.

Returns:

  • (Array<Symbol>)

    Returns an array of symbolized data attribute names.


124
125
126
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 124

def data_attributes
  @data_attributes.dup
end

.identifiersArray<Symbol>

Returns:

  • (Array<Symbol>)

See Also:


100
101
102
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 100

def identifiers
  @identifiers.dup
end

Instance Method Details

#dataStruct

Returns:

  • (Struct)

27
28
29
30
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 27

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if #data has been loaded.

Returns:

  • (Boolean)

    Returns true if #data has been loaded.


33
34
35
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 33

def data_loaded?
  !@data.nil?
end

#loadself Also known as: reload

Note:

Calling this method will send a request to AWS.

Loads data for this resource.

Returns:

  • (self)

40
41
42
43
44
45
46
47
# File 'aws-sdk-resources/lib/aws-sdk-resources/resource.rb', line 40

def load
  if load_operation = self.class.load_operation
    @data = load_operation.call(resource:self, client:client)
    self
  else
    raise NotImplementedError, "#load not defined for #{self.class.name}"
  end
end