Class: Rack::Idempotency::RequestStorage

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/idempotency/request_storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(store, request) ⇒ RequestStorage

Returns a new instance of RequestStorage.



4
5
6
7
# File 'lib/rack/idempotency/request_storage.rb', line 4

def initialize(store, request)
  @store   = store
  @request = request
end

Instance Method Details

#readObject



9
10
11
12
13
14
# File 'lib/rack/idempotency/request_storage.rb', line 9

def read
  return unless request.idempotency_key

  stored = store.read(storage_key)
  JSON.parse(stored) if stored
end

#write(response) ⇒ Object



16
17
18
19
20
# File 'lib/rack/idempotency/request_storage.rb', line 16

def write(response)
  return unless request.idempotency_key

  store.write(storage_key, response.to_json)
end