Class: AWS::SimpleDB::Attribute
- Inherits:
-
Object
- Object
- AWS::SimpleDB::Attribute
- Includes:
- Core::Model, ConsistentReadOption, DeleteAttributes, PutAttributes, Enumerable
- Defined in:
- lib/aws/simple_db/attribute.rb
Overview
Represents a single named item attribute in SimpleDB.
Instance Attribute Summary collapse
-
#item ⇒ Item
readonly
The item this attribute belongs to.
-
#name ⇒ String
readonly
The name of this attribute.
Attributes included from Core::Model
Instance Method Summary collapse
-
#add(*values) ⇒ nil
(also: #<<)
Appends values to this attribute.
-
#delete(*values) ⇒ nil
Deletes this attribute or specific values from this attribute.
-
#each(options = {}) {|attribute_value| ... } ⇒ nil
Yields once for each value on this attribute.
-
#initialize(item, name, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
-
#set(*values) ⇒ nil
Sets all values for this attribute, replacing current values.
-
#values(options = {}) ⇒ Array<String>
Returns all values for this attribute as an array of strings.
Methods included from ConsistentReadOption
Methods included from Core::Model
#client, #config_prefix, #inspect
Constructor Details
#initialize(item, name, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
27 28 29 30 31 |
# File 'lib/aws/simple_db/attribute.rb', line 27 def initialize item, name, = {} @item = item @name = name super end |
Instance Attribute Details
#item ⇒ Item (readonly)
Returns The item this attribute belongs to.
34 35 36 |
# File 'lib/aws/simple_db/attribute.rb', line 34 def item @item end |
#name ⇒ String (readonly)
Returns The name of this attribute.
37 38 39 |
# File 'lib/aws/simple_db/attribute.rb', line 37 def name @name end |
Instance Method Details
#add(*values) ⇒ nil Also known as: <<
Appends values to this attribute. Duplicate values are ignored by SimpleDB.
67 68 69 70 |
# File 'lib/aws/simple_db/attribute.rb', line 67 def add *values put(values, false) nil end |
#delete(*values) ⇒ nil
Deletes this attribute or specific values from this attribute.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/aws/simple_db/attribute.rb', line 87 def delete *values expect_opts = values.pop if values.last.kind_of?(Hash) if values.empty? delete_named_attributes(name, expect_opts || {}) else delete_attribute_values(Hash[[[name, values]]]. merge(expect_opts || {})) end nil end |
#each(options = {}) {|attribute_value| ... } ⇒ nil
Yields once for each value on this attribute.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/aws/simple_db/attribute.rb', line 108 def each = {}, &block resp = client.get_attributes( :domain_name => item.domain.name, :item_name => item.name, :attribute_names => [name], :consistent_read => consistent_read()) resp.attributes.each do |attribute| yield(attribute.value) end nil end |
#set(*values) ⇒ nil
Sets all values for this attribute, replacing current values.
49 50 51 52 |
# File 'lib/aws/simple_db/attribute.rb', line 49 def set *values put(values, true) nil end |
#values(options = {}) ⇒ Array<String>
Returns all values for this attribute as an array of strings.
135 136 137 138 139 140 141 |
# File 'lib/aws/simple_db/attribute.rb', line 135 def values = {} values = [] self.each() do |value| values << value end values end |