Class: Amazon::SDB::Item
- Inherits:
-
Object
- Object
- Amazon::SDB::Item
- Includes:
- Enumerable
- Defined in:
- lib/amazon_sdb/item.rb
Overview
An item from SimpleDB. 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
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#destroy! ⇒ Object
Deletes the item in SimpleDB.
- #each ⇒ Object
- #each_pair ⇒ Object
-
#empty? ⇒ Boolean
Returns true if the attributes are empty.
-
#get(key) ⇒ Object
Reloads the item if necessary.
-
#initialize(domain, key, multimap = nil) ⇒ Item
constructor
A new instance of Item.
-
#reload! ⇒ Object
Reloads from the domain.
-
#save ⇒ Object
Saves the item back (like a put_attributes with :replace => :all.
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
#attributes ⇒ Object
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/amazon_sdb/item.rb', line 8 def attributes @attributes end |
#key ⇒ Object
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
49 50 51 |
# File 'lib/amazon_sdb/item.rb', line 49 def [](key) get(key) end |
#destroy! ⇒ Object
Deletes the item in SimpleDB
32 33 34 |
# File 'lib/amazon_sdb/item.rb', line 32 def destroy! @domain.delete_attributes(@key) end |
#each ⇒ Object
53 54 55 |
# File 'lib/amazon_sdb/item.rb', line 53 def each @attributes.each end |
#each_pair ⇒ Object
57 58 59 |
# File 'lib/amazon_sdb/item.rb', line 57 def each_pair @attributes.each_pair end |
#empty? ⇒ Boolean
Returns true if the attributes are empty
25 26 27 28 |
# File 'lib/amazon_sdb/item.rb', line 25 def empty? return true if @attributes.nil? @attributes.size == 0 end |
#get(key) ⇒ Object
Reloads the item if necessary
44 45 46 47 |
# File 'lib/amazon_sdb/item.rb', line 44 def get(key) reload! if @attributes.nil? @attributes.get(key) end |
#reload! ⇒ Object
Reloads from the domain
18 19 20 21 |
# File 'lib/amazon_sdb/item.rb', line 18 def reload! item = @domain.get_attributes(@key) @attributes = item.attributes end |
#save ⇒ Object
Saves the item back (like a put_attributes with :replace => :all
38 39 40 |
# File 'lib/amazon_sdb/item.rb', line 38 def save @domain.put_attributes(@key, @attributes, :replace => :all) end |