Class: Aws::Resources::Builder

Inherits:
Object
  • Object
show all
Includes:
Options
Defined in:
aws-sdk-resources/lib/aws-sdk-resources/builder.rb

Overview

A Builder construct resource objects. It extracts resource identifiers for the objects it builds from another resource object and/or an AWS response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Builder

Returns a new instance of Builder

Options Hash (options):


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

def initialize(options = {})
  @resource_class = options[:resource_class]
  @sources = options[:sources] || []
end

Instance Attribute Details

#resource_classClass<Resource> (readonly)


19
20
21
# File 'aws-sdk-resources/lib/aws-sdk-resources/builder.rb', line 19

def resource_class
  @resource_class
end

#sourcesArray<BuilderSources::Source> (readonly)


23
24
25
# File 'aws-sdk-resources/lib/aws-sdk-resources/builder.rb', line 23

def sources
  @sources
end

Instance Method Details

#build(options = {}) ⇒ Resource+

Returns a resource object or an array of resource objects if #plural?.


35
36
37
38
39
40
41
42
43
44
# File 'aws-sdk-resources/lib/aws-sdk-resources/builder.rb', line 35

def build(options = {})
  identifier_map = @sources.each.with_object({}) do |source, hash|
    hash[source.target] = source.extract(options)
  end
  if plural?
    build_batch(identifier_map, options)
  else
    build_one(identifier_map, options)
  end
end

#plural?Boolean


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

def plural?
  @sources.any?(&:plural?)
end