Class: AWS::SimpleDB::ItemData

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

Overview

Holds the data for a SimpleDB item. While Item only proxies requests to return data, this class actually stores data returned by a query. For example, you can use this to get the list of items whose titles are palindromes using only a single request to SimpleDB (not counting pagination):

items.enum_for(:select).
  select { |data| data.title == data.title.to_s.reverse }.
  map { |data| data.item }

The AWS::SimpleDB::ItemCollection#select call yields instances of ItemData, and the map call in the example above gets the list of corresponding Item instances.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ItemData

Returns a new instance of ItemData.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/aws/simple_db/item_data.rb', line 33

def initialize(opts = {})
  @name = opts[:name]
  @attributes = opts[:attributes]
  @domain = opts[:domain]

  if obj = opts[:response_object]
    @name ||= obj[:name]
    if obj[:attributes]
      @attributes ||= begin
        attributes = {}
        obj[:attributes].each do |attr|
          attributes[attr[:name]] ||= []
          attributes[attr[:name]] << attr[:value]
        end
        attributes
      end
    end
  end
end

Instance Attribute Details

#attributesHash (readonly)

Returns A hash of attribute names to arrays of values.

Returns:

  • (Hash)

    A hash of attribute names to arrays of values.



57
58
59
# File 'lib/aws/simple_db/item_data.rb', line 57

def attributes
  @attributes
end

#domainDomain (readonly)

Returns The domain from which the item data was retrieved.

Returns:

  • (Domain)

    The domain from which the item data was retrieved.



60
61
62
# File 'lib/aws/simple_db/item_data.rb', line 60

def domain
  @domain
end

#nameString (readonly)

Returns The item name.

Returns:

  • (String)

    The item name.



54
55
56
# File 'lib/aws/simple_db/item_data.rb', line 54

def name
  @name
end

Instance Method Details

#itemItem

Returns the AWS::SimpleDB::Item corresponding to this ItemData; you can use this to perform further operations on the item, or to fetch its most recent data.

Returns:

  • (Item)

    The item this data belongs to.



66
67
68
# File 'lib/aws/simple_db/item_data.rb', line 66

def item
  domain.items[name]
end