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

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>?


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

def client_class
  @client_class
end

.load_operationOperations::LoadOperation?


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

def load_operation
  @load_operation
end

.resource_nameString?


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


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


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.


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


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>


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

def data_attributes
  @data_attributes.dup
end

.identifiersArray<Symbol>


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

def identifiers
  @identifiers.dup
end

Instance Method Details

#dataStruct


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


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.


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