Class: ConfigurationService::Provider::StubStore

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/configuration_service/provider/stub_store.rb

Overview

A singleton store for the Stub service provider

Examples:

Storing data and metadata


data = {"username" => "sheldonh", "password" => "secret123"}
 = {"version" => "1.0.0"}
StubStore.instance.store("acme", data, )

Fetching data and metadata


data,  = StubStore.instance.fetch("acme")
# data     -> {"username" => "sheldonh", "password" => "secret123"}
# metadata -> {"version" => "1.0.0"}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.instanceConfigurationService::ProviderRegistry

The singleton registry instance



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/configuration_service/provider/stub_store.rb', line 29

class StubStore

  include Singleton

  ##
  # Fetch configuration data and metadata
  #
  # @param [String] identifier the configuration identifier
  #
  # @return [Array<Hash>] data and metadata as a tuple
  #
  def fetch(identifier)
    @configurations.fetch(identifier)
  end

  ##
  # Store configuration data and metadata
  #
  # @param [String] identifier the configuration identifier
  # @param [Hash] data the configuration data
  # @param [Hash] metadata the configuration metadata
  #
  def store(identifier, data, )
    @configurations.store(identifier, [data, ])
  end

  ##
  # Delete configuration data and metadata
  #
  # It is not an error to delete non-existent configuration
  #
  # @param [String] identifier the configuration identifier
  #
  def delete(identifier)
    @configurations.delete(identifier)
    nil
  end

  ##
  # Delete all configuration data and metadata
  #
  def clear
    @configurations.clear
  end

  # @private
  def initialize
    @configurations = {}
  end

end

Instance Method Details

#clearObject

Delete all configuration data and metadata



70
71
72
# File 'lib/configuration_service/provider/stub_store.rb', line 70

def clear
  @configurations.clear
end

#delete(identifier) ⇒ Object

Delete configuration data and metadata

It is not an error to delete non-existent configuration



62
63
64
65
# File 'lib/configuration_service/provider/stub_store.rb', line 62

def delete(identifier)
  @configurations.delete(identifier)
  nil
end

#fetch(identifier) ⇒ Array<Hash>

Fetch configuration data and metadata



40
41
42
# File 'lib/configuration_service/provider/stub_store.rb', line 40

def fetch(identifier)
  @configurations.fetch(identifier)
end

#store(identifier, data, metadata) ⇒ Object

Store configuration data and metadata



51
52
53
# File 'lib/configuration_service/provider/stub_store.rb', line 51

def store(identifier, data, )
  @configurations.store(identifier, [data, ])
end