Class: Amazon::SDB::Item

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/amazon_sdb/item.rb

Overview

An item from sdb. This basically is a key for the item in the domain and a Multimap of the attributes. You should never call Item#new, instead it is returned by various methods in Domain and ResultSet

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, key, multimap = nil) ⇒ Item

Returns a new instance of Item.



10
11
12
13
14
# File 'lib/amazon_sdb/item.rb', line 10

def initialize(domain, key, multimap=nil)
  @domain = domain
  @key = key
  @attributes = multimap
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



8
9
10
# File 'lib/amazon_sdb/item.rb', line 8

def attributes
  @attributes
end

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/amazon_sdb/item.rb', line 8

def key
  @key
end

Instance Method Details

#[](key) ⇒ Object



38
39
40
# File 'lib/amazon_sdb/item.rb', line 38

def [](key)
  get(key)
end

#destroy!Object



25
26
27
# File 'lib/amazon_sdb/item.rb', line 25

def destroy!
  @domain.delete_attributes(@key)
end

#eachObject



42
43
44
# File 'lib/amazon_sdb/item.rb', line 42

def each
  @attributes.each
end

#each_pairObject



46
47
48
# File 'lib/amazon_sdb/item.rb', line 46

def each_pair
  @attributes.each_pair
end

#empty?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/amazon_sdb/item.rb', line 21

def empty?
  @attributes.size == 0
end

#get(key) ⇒ Object



33
34
35
36
# File 'lib/amazon_sdb/item.rb', line 33

def get(key)
  reload! if @attributes.nil?
  @attributes.get(key)
end

#reload!Object



16
17
18
19
# File 'lib/amazon_sdb/item.rb', line 16

def reload!
  item = @domain.get_attributes(@key)
  @attributes = item.attributes
end

#saveObject



29
30
31
# File 'lib/amazon_sdb/item.rb', line 29

def save
  @domain.put_attributes(@key, @attributes)
end