Class: Rubyists::Dapr::Client::State
- Inherits:
-
Object
- Object
- Rubyists::Dapr::Client::State
- Includes:
- Rubyists::Dapr::Client, SemanticLogger::Loggable
- Defined in:
- lib/dapr/client/state.rb
Overview
The State class is a client for the Dapr State Management Building block Info here: docs.dapr.io/developing-applications/building-blocks/state-management/
Defined Under Namespace
Classes: Item
Constant Summary collapse
- Empty =
Google::Protobuf::Empty
- Runtime =
Client::Runtime
- GetBulkStateResponse =
Runtime::GetBulkStateResponse
- GetStateRequest =
Runtime::GetBulkStateRequest
- SaveStateRequest =
Runtime::SaveStateRequest
- DEFAULT_STORE_NAME =
'statestore'
Constants included from Rubyists::Dapr::Client
DAPR_PORT, DAPR_STUB, DAPR_URI
Instance Attribute Summary collapse
-
#store_name ⇒ Object
readonly
Returns the value of attribute store_name.
Class Method Summary collapse
-
.get(*keys, store_name: DEFAULT_STORE_NAME, metadata: {}) ⇒ GetBulkStateResponse
The response from the Dapr State Management component.
-
.set(states, store_name: DEFAULT_STORE_NAME, metadata: {}) ⇒ Empty
The response from the Dapr State Management component.
Instance Method Summary collapse
-
#get(keys, metadata: {}) ⇒ Array<BulkStateItem>
Array of items returned by the state store.
-
#initialize(store_name) ⇒ State
constructor
Initialize the State Management client.
-
#set(states, metadata: {}) ⇒ Empty
The response from the Dapr State Management component (Empty means success).
Methods included from Rubyists::Dapr::Client
client, #client, singleton, #singleton
Constructor Details
#initialize(store_name) ⇒ State
Initialize the State Management client
46 47 48 |
# File 'lib/dapr/client/state.rb', line 46 def initialize(store_name) @store_name = store_name end |
Instance Attribute Details
#store_name ⇒ Object (readonly)
Returns the value of attribute store_name.
15 16 17 |
# File 'lib/dapr/client/state.rb', line 15 def store_name @store_name end |
Class Method Details
.get(*keys, store_name: DEFAULT_STORE_NAME, metadata: {}) ⇒ GetBulkStateResponse
Returns The response from the Dapr State Management component.
30 31 32 |
# File 'lib/dapr/client/state.rb', line 30 def self.get(*keys, store_name: DEFAULT_STORE_NAME, metadata: {}) new(store_name).get(keys, metadata:) end |
.set(states, store_name: DEFAULT_STORE_NAME, metadata: {}) ⇒ Empty
Returns The response from the Dapr State Management component.
39 40 41 |
# File 'lib/dapr/client/state.rb', line 39 def self.set(states, store_name: DEFAULT_STORE_NAME, metadata: {}) new(store_name).set(states, metadata:) end |
Instance Method Details
#get(keys, metadata: {}) ⇒ Array<BulkStateItem>
Returns Array of items returned by the state store.
54 55 56 57 58 |
# File 'lib/dapr/client/state.rb', line 54 def get(keys, metadata: {}) logger.debug('Getting state', keys:, store_name:, metadata:) response = singleton.get_bulk_state GetStateRequest.new(store_name:, keys:, metadata:) response.items.to_h { |i| [i.key, Item.new(data: i.data, etag: i.etag, metadata: i.)] } end |
#set(states, metadata: {}) ⇒ Empty
Returns The response from the Dapr State Management component (Empty means success).
64 65 66 67 68 69 |
# File 'lib/dapr/client/state.rb', line 64 def set(states, metadata: {}) states = states.map { |key, value| { key:, value:, metadata: } } request = SaveStateRequest.new(store_name:, states:) logger.debug('Setting state', states:, store_name:) singleton.save_state request end |