Module: Adapter::SimpleDB

Defined in:
lib/adapter/simpledb.rb,
lib/adapter/simpledb/version.rb

Constant Summary collapse

NonHashValueKeyName =
'_value'
ArrayFillName =
'_array'
VERSION =
"0.1.1"

Instance Method Summary collapse

Instance Method Details

#clearObject



22
23
24
25
# File 'lib/adapter/simpledb.rb', line 22

def clear
  client.delete_domain(domain)
  client.create_domain(domain)
end

#decode(value) ⇒ Object



32
33
34
35
36
37
# File 'lib/adapter/simpledb.rb', line 32

def decode(value)
  value = value.body['Attributes']
  return if value.nil? || value == {}
  value = fix_arrays(value)
  value.key?(NonHashValueKeyName) ? value[NonHashValueKeyName] : value
end

#delete(key) ⇒ Object



18
19
20
# File 'lib/adapter/simpledb.rb', line 18

def delete(key)
  read(key).tap { client.delete_attributes(domain, key_for(key)) }
end

#encode(value) ⇒ Object



27
28
29
30
# File 'lib/adapter/simpledb.rb', line 27

def encode(value)
  value = {NonHashValueKeyName => value} unless value.is_a?(Hash)
  value.each {|key, v| v.unshift(ArrayFillName) if v.is_a?(Array) }
end

#read(key) ⇒ Object



9
10
11
# File 'lib/adapter/simpledb.rb', line 9

def read(key)
  decode(client.get_attributes(domain, key_for(key), 'ConsistentRead' => options[:consistent_read]))
end

#write(key, value) ⇒ Object



13
14
15
16
# File 'lib/adapter/simpledb.rb', line 13

def write(key, value)
  encoded_value = encode(value)
  client.put_attributes(domain, key_for(key), encoded_value, :replace => encoded_value.keys)
end