Class: Aws::Resources::Builder
- Inherits:
-
Object
- Object
- Aws::Resources::Builder
- 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
- #resource_class ⇒ Class<Resource> readonly
-
#sources ⇒ Array<BuilderSources::Source>
readonly
A list of resource identifier sources.
Instance Method Summary collapse
-
#build(options = {}) ⇒ Resource+
Returns a resource object or an array of resource objects if #plural?.
-
#initialize(options = {}) ⇒ Builder
constructor
A new instance of Builder.
-
#plural? ⇒ Boolean
Returns ‘true` if this builder returns an array of resource objects from #build.
Constructor Details
#initialize(options = {}) ⇒ Builder
Returns a new instance of Builder.
13 14 15 16 |
# File 'lib/aws-sdk-resources/builder.rb', line 13 def initialize( = {}) @resource_class = [:resource_class] @sources = [:sources] || [] end |
Instance Attribute Details
#resource_class ⇒ Class<Resource> (readonly)
19 20 21 |
# File 'lib/aws-sdk-resources/builder.rb', line 19 def resource_class @resource_class end |
#sources ⇒ Array<BuilderSources::Source> (readonly)
Returns A list of resource identifier sources.
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?.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/aws-sdk-resources/builder.rb', line 35 def build( = {}) identifier_map = @sources.each.with_object({}) do |source, hash| hash[source.target] = source.extract() end if plural? build_batch(identifier_map, ) else build_one(identifier_map, ) end end |
#plural? ⇒ 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 |