Class: AWS::SimpleDB::AttributeCollection
- Inherits:
-
Object
- Object
- AWS::SimpleDB::AttributeCollection
- Includes:
- Enumerable
- Defined in:
- lib/aws/simple_db/attribute_collection.rb
Instance Attribute Summary collapse
-
#item ⇒ Item
readonly
The item this collection belongs to.
Instance Method Summary collapse
-
#[](attribute_name) ⇒ Item
Returns an Attribute with the given name.
-
#[]=(attribute_name, *values) ⇒ Object
Sets the values for a given attribute.
-
#add(attributes) ⇒ nil
Adds values to attributes on the #item.
-
#delete(*args) ⇒ Object
Delete one or more attributes from #item.
-
#each(options = {}) {|attribute| ... } ⇒ nil
Yields all attribute for this item.
-
#each_value(options = {}) {|attribute_name, attribute_value| ... } ⇒ nil
Yields all attribute values with their names.
- #initialize(item, options = {}) ⇒ AttributeCollection constructor
-
#put(options = {}) ⇒ nil
Perform a mixed update of added and replace attributes.
-
#replace(attributes) ⇒ nil
(also: #set)
Replaces attributes for the #item.
-
#to_h(options = {}) ⇒ Hash
Returns a hash of all attributes (names and values).
Constructor Details
#initialize(item, options = {}) ⇒ AttributeCollection
26 27 28 29 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 26 def initialize item, = {} @item = item super end |
Instance Attribute Details
#item ⇒ Item (readonly)
Returns The item this collection belongs to.
32 33 34 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 32 def item @item end |
Instance Method Details
#[](attribute_name) ⇒ Item
This does not make a request to SimpleDB.
Returns an Attribute with the given name.
You can ask for any attribute by name. The attribute may or may not actually exist in SimpleDB.
48 49 50 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 48 def [] attribute_name Attribute.new(item, attribute_name.to_s) end |
#[]=(attribute_name, *values) ⇒ Object
Sets the values for a given attribute.
59 60 61 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 59 def []= attribute_name, *values self[attribute_name].set(*values) end |
#add(attributes) ⇒ nil
Adds values to attributes on the #item.
The attributes_hash
should have attribute names as keys. The
hash values should be either strings or arrays of strings.
@param[Hash] attribute_hash
158 159 160 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 158 def add attributes do_put(attribute_hashes(attributes, false), attributes) end |
#delete(attributes) ⇒ nil #delete(*attribute_names) ⇒ nil
Delete one or more attributes from #item.
229 230 231 232 233 234 235 236 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 229 def delete *args if args.size == 1 and args.first.kind_of?(Hash) delete_attribute_values(args.first) else delete_named_attributes(*args) end nil end |
#each(options = {}) {|attribute| ... } ⇒ nil
Yields all attribute for this item.
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 112 def each = {}, &block yielded = {} each_value() do |attribute_name, attribute_value| unless yielded[attribute_name] attribute = self[attribute_name] yield(attribute) yielded[attribute_name] = true end end nil end |
#each_value(options = {}) {|attribute_name, attribute_value| ... } ⇒ nil
Yields all attribute values with their names.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 79 def each_value = {}, &block list = client.get_attributes( :domain_name => item.domain.name, :item_name => item.name, :consistent_read => consistent_read()) list.attributes.each do |attribute| attribute_name = attribute.name attribute_value = attribute.value yield(attribute_name, attribute_value) end nil end |
#put(options = {}) ⇒ nil
Perform a mixed update of added and replace attributes.
179 180 181 182 183 184 185 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 179 def put = {} add = [:add] || {} replace = [:replace] || {} attributes = attribute_hashes(add, false) attributes += attribute_hashes(replace, true) do_put(attributes, ) end |
#replace(attributes) ⇒ nil Also known as: set
Replaces attributes for the #item.
The attributes_hash
should have attribute names as keys. The
hash values should be either strings or arrays of strings.
Attributes not named in this hash are left alone. Attributes named in this hash are replaced.
140 141 142 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 140 def replace attributes do_put(attribute_hashes(attributes, true), attributes) end |
#to_h(options = {}) ⇒ Hash
Returns a hash of all attributes (names and values). The attribute names are strings and the values are arrays of strings.
200 201 202 203 204 205 206 207 |
# File 'lib/aws/simple_db/attribute_collection.rb', line 200 def to_h = {} hash = {} each_value() do |attribute_name,attribute_value| hash[attribute_name] ||= [] hash[attribute_name] << attribute_value end hash end |