Class: Aws::Resources::Builder

Inherits:
Object
  • Object
show all
Includes:
Options
Defined in:
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.

Parameters:

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

    a customizable set of options

Options Hash (options):



13
14
15
16
# File '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)

Returns:



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

def resource_class
  @resource_class
end

#sourcesArray<BuilderSources::Source> (readonly)

Returns A list of resource identifier sources.

Returns:



23
24
25
# File '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?.

Parameters:

  • [Resource] (Hash)

    a customizable set of options

  • [Seahorse::Client::Response] (Hash)

    a customizable set of options

Returns:



35
36
37
38
39
40
41
42
43
44
# File '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

Returns ‘true` if this builder returns an array of resource objects from #build.

Returns:

  • (Boolean)

    Returns ‘true` if this builder returns an array of resource objects from #build.



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

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