Class: Google::ObjectStore

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/google/object_store.rb

Overview

A helper class to aggregate all resources when multiple providers produce them at the same time. This singleton is used to collect different “flavors” of resources, managed by different providers, when the client does not care which provider created it.

For example when authenticating requests, as long as the resource honors the “authenticate” API which provider, or which parameters it needed to create itself matters little to the consumer of the authenticator.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObjectStore

Returns a new instance of ObjectStore.



28
29
30
# File 'lib/google/object_store.rb', line 28

def initialize
  @resources = {}
end

Instance Attribute Details

#resourcesObject (readonly)

Returns the value of attribute resources.



26
27
28
# File 'lib/google/object_store.rb', line 26

def resources
  @resources
end

Instance Method Details

#[](type) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/google/object_store.rb', line 39

def [](type)
  if @resources[type].nil?
    []
  else
    @resources[type]
  end
end

#add(type, resource) ⇒ Object

Adds an instance of the resource to the global collection.



33
34
35
36
37
# File 'lib/google/object_store.rb', line 33

def add(type, resource)
  Puppet.debug "Registering resource #{resource}"
  @resources[type] = [] if @resources[type].nil?
  @resources[type] << resource
end