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



33
34
35
36
37
# File 'lib/aws/simple_db/item.rb', line 33

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

Instance Attribute Details

#domainDomain (readonly)



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

def domain
  @domain
end

#nameString (readonly)



43
44
45
# File 'lib/aws/simple_db/item.rb', line 43

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



82
83
84
85
86
# File 'lib/aws/simple_db/item.rb', line 82

def == other
  other.is_a?(Item) and 
  other.domain == domain and
  other.name == name
end

#attributesAttributeCollection



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

def attributes
  AttributeCollection.new(self)
end

#data(options = {}) ⇒ ItemData

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



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

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.

Options Hash (options):

  • :if (Hash)

    Pass a hash with a single key (attribute name) and a single value (the attribute value). This causes the delete to become conditional.

  • :unless (String, Symbol)

    Pass an attribute name. This causes the delete to become conditional on that attribute not existing.



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

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