Class: Blobby::LoggingStore

Inherits:
Object
  • Object
show all
Defined in:
lib/blobby/logging_store.rb

Overview

A store decorator that logs writes and deletes

Defined Under Namespace

Classes: StoredObject

Instance Method Summary collapse

Constructor Details

#initialize(store, store_name, logger) ⇒ LoggingStore

Returns a new instance of LoggingStore.



9
10
11
12
13
# File 'lib/blobby/logging_store.rb', line 9

def initialize(store, store_name, logger)
  @store = store
  @store_name = store_name
  @logger = logger
end

Instance Method Details

#[](key) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/blobby/logging_store.rb', line 19

def [](key)
  StoredObject.new(
    store[key],
    :on_write => -> { logger.info(%(wrote to #{key.inspect} in #{store_name})) },
    :on_delete => -> { logger.info(%(deleted #{key.inspect} from #{store_name})) }
  )
end

#available?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/blobby/logging_store.rb', line 15

def available?
  store.available?
end