Class: AWS::SimpleDB::Item

Inherits:
Object
  • Object
show all
Includes:
Core::Model, ConsistentReadOption, ExpectConditionOption
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

Attributes included from Core::Model

#config

Instance Method Summary collapse

Methods included from ConsistentReadOption

#consistent_read

Methods included from Core::Model

#client, #config_prefix, #inspect

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: {})


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)

Returns The domain this item belongs to.

Returns:

  • (Domain)

    The domain this item belongs to.



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

def domain
  @domain
end

#nameString (readonly)

Returns The item name.

Returns:

  • (String)

    The item name.



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

Returns A collection representing all attributes for this item.

Returns:



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.

Returns:

  • (ItemData)

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



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.data)
end

#delete(options = {}) ⇒ nil

Deletes the item and all of its attributes from SimpleDB.

Parameters:

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

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.

Returns:

  • (nil)


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