Class: AWS::SimpleDB::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/aws/simple_db/item.rb

Overview

Represents a single item in a SimpleDB domain. You can use this class to delete the item or get its data. You can also use it to access the AttributeCollection for the item in order to add, remove, or read the item’s attributes.

item = AWS::SimpleDB.new.domains['mydomain'].items['item-id']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(domain, name, options = {}) ⇒ Item

Returns a new instance of Item.

Parameters:

  • domain (Domain)

    The domain the item belongs to

  • name (String)

    The name of the item in SimpleDB.

  • options (Hash) (defaults to: {})


39
40
41
42
43
# File 'lib/aws/simple_db/item.rb', line 39

def initialize domain, name, options = {}
  @domain = domain
  @name = name
  super
end

Instance Attribute Details

#domainDomain (readonly)

Returns The domain this item belongs to.

Returns:

  • (Domain)

    The domain this item belongs to.



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

def domain
  @domain
end

#nameString (readonly)

Returns The item name.

Returns:

  • (String)

    The item name.



49
50
51
# File 'lib/aws/simple_db/item.rb', line 49

def name
  @name
end

Instance Method Details

#attributesAttributeCollection

Returns A collection representing all attributes for this item.

Returns:



53
54
55
# File 'lib/aws/simple_db/item.rb', line 53

def attributes
  AttributeCollection.new(self)
end

#data(options = {}) ⇒ ItemData

Returns all of the item’s attributes in an AWS::SimpleDB::ItemData instance.

Returns:

  • (ItemData)

    An object with all of the loaded attribute names and values for this item.



72
73
74
75
76
77
78
79
# File 'lib/aws/simple_db/item.rb', line 72

def data options = {}
  get_opts = {}
  get_opts[:domain_name] = domain.name
  get_opts[:item_name] = name
  get_opts[:consistent_read] = consistent_read(options)
  r = client.get_attributes(get_opts)
  ItemData.new(:name => name, :domain => domain, :response_object => r)
end

#delete(options = {}) ⇒ nil

Deletes the item and all of its attributes from SimpleDB.

Returns:

  • (nil)


59
60
61
62
63
64
65
66
67
# File 'lib/aws/simple_db/item.rb', line 59

def delete options = {}
  delete_opts = {}
  delete_opts[:domain_name] = domain.name
  delete_opts[:item_name] = name
  delete_opts[:expected] = expect_condition_opts(options)
  delete_opts.delete(:expected) if delete_opts[:expected].empty?
  client.delete_attributes(delete_opts)
  nil
end