Method: CouchbaseModelLogging::Logger#add

Defined in:
lib/couchbase_model_logging/logger.rb

#add(key, hash = { }) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/couchbase_model_logging/logger.rb', line 26

def add(key, hash = { })
  yaml     = encode hash
  pref_key = prefixed_key_for key
  begin
    client.append pref_key, yaml, :format => :plain
  rescue ::Couchbase::Error::NotStored
    begin
      client.add pref_key, yaml, :format => :plain
    rescue ::Couchbase::Error::KeyExists
      client.append pref_key, yaml, :format => :plain
    end
  end
end