aws-sdk 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/aws.rb +2 -0
- data/lib/aws/api_config/DynamoDB-2011-12-05.yml +721 -0
- data/lib/aws/core.rb +10 -1
- data/lib/aws/core/client.rb +17 -12
- data/lib/aws/core/configuration.rb +13 -3
- data/lib/aws/core/configured_json_client_methods.rb +71 -0
- data/lib/aws/core/lazy_error_classes.rb +7 -2
- data/lib/aws/core/option_grammar.rb +67 -13
- data/lib/aws/core/resource.rb +9 -1
- data/lib/aws/core/session_signer.rb +95 -0
- data/lib/aws/dynamo_db.rb +169 -0
- data/lib/aws/dynamo_db/attribute_collection.rb +460 -0
- data/lib/aws/dynamo_db/batch_get.rb +206 -0
- data/lib/aws/dynamo_db/client.rb +119 -0
- data/lib/aws/dynamo_db/config.rb +20 -0
- data/lib/aws/dynamo_db/errors.rb +57 -0
- data/lib/aws/dynamo_db/expectations.rb +40 -0
- data/lib/aws/dynamo_db/item.rb +130 -0
- data/lib/aws/dynamo_db/item_collection.rb +837 -0
- data/lib/aws/{record/optimistic_locking.rb → dynamo_db/item_data.rb} +9 -12
- data/lib/aws/{record/attributes/boolean.rb → dynamo_db/keys.rb} +15 -23
- data/lib/aws/dynamo_db/primary_key_element.rb +47 -0
- data/lib/aws/dynamo_db/request.rb +78 -0
- data/lib/aws/{record/attributes/float.rb → dynamo_db/resource.rb} +10 -25
- data/lib/aws/dynamo_db/table.rb +418 -0
- data/lib/aws/dynamo_db/table_collection.rb +165 -0
- data/lib/aws/dynamo_db/types.rb +86 -0
- data/lib/aws/ec2/resource_tag_collection.rb +3 -1
- data/lib/aws/record.rb +36 -8
- data/lib/aws/record/abstract_base.rb +642 -0
- data/lib/aws/record/attributes.rb +384 -0
- data/lib/aws/record/dirty_tracking.rb +0 -1
- data/lib/aws/record/errors.rb +0 -8
- data/lib/aws/record/hash_model.rb +163 -0
- data/lib/aws/record/hash_model/attributes.rb +182 -0
- data/lib/aws/record/hash_model/finder_methods.rb +178 -0
- data/lib/aws/record/hash_model/scope.rb +108 -0
- data/lib/aws/record/model.rb +429 -0
- data/lib/aws/record/model/attributes.rb +377 -0
- data/lib/aws/record/model/finder_methods.rb +232 -0
- data/lib/aws/record/model/scope.rb +213 -0
- data/lib/aws/record/scope.rb +43 -169
- data/lib/aws/record/validations.rb +11 -11
- data/lib/aws/s3/client.rb +9 -6
- data/lib/aws/s3/object_collection.rb +1 -1
- data/lib/aws/simple_db/expect_condition_option.rb +1 -1
- data/lib/aws/simple_db/item_collection.rb +5 -3
- data/lib/aws/sts/client.rb +9 -0
- metadata +73 -30
- data/lib/aws/record/attribute.rb +0 -94
- data/lib/aws/record/attribute_macros.rb +0 -312
- data/lib/aws/record/attributes/date.rb +0 -89
- data/lib/aws/record/attributes/datetime.rb +0 -86
- data/lib/aws/record/attributes/integer.rb +0 -68
- data/lib/aws/record/attributes/sortable_float.rb +0 -60
- data/lib/aws/record/attributes/sortable_integer.rb +0 -95
- data/lib/aws/record/attributes/string.rb +0 -69
- data/lib/aws/record/base.rb +0 -828
- data/lib/aws/record/finder_methods.rb +0 -230
- data/lib/aws/record/scopes.rb +0 -55
@@ -1,230 +0,0 @@
|
|
1
|
-
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
-
# may not use this file except in compliance with the License. A copy of
|
5
|
-
# the License is located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is
|
10
|
-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
-
# ANY KIND, either express or implied. See the License for the specific
|
12
|
-
# language governing permissions and limitations under the License.
|
13
|
-
|
14
|
-
require 'aws/simple_db'
|
15
|
-
require 'aws/record/scope'
|
16
|
-
|
17
|
-
module AWS
|
18
|
-
module Record
|
19
|
-
|
20
|
-
module FinderMethods
|
21
|
-
|
22
|
-
# @param [String] id The id of the record to load.
|
23
|
-
# @param [Hash] options
|
24
|
-
# @option options [String] :domain Specifies what domain
|
25
|
-
# should be searched.
|
26
|
-
# @raise [RecordNotFound] Raises a record not found exception if there
|
27
|
-
# was no data found for the given id.
|
28
|
-
# @return [Record::Base] Returns the record, as a sub-class of
|
29
|
-
# Record::Base
|
30
|
-
def find_by_id id, options = {}
|
31
|
-
|
32
|
-
domain = sdb_domain(options[:domain])
|
33
|
-
|
34
|
-
data = domain.items[id].data.attributes
|
35
|
-
|
36
|
-
raise RecordNotFound, "no data found for id: #{id}" if data.empty?
|
37
|
-
|
38
|
-
obj = self.new(:domain => domain)
|
39
|
-
obj.send(:hydrate, id, data)
|
40
|
-
obj
|
41
|
-
|
42
|
-
end
|
43
|
-
alias_method :[], :find_by_id
|
44
|
-
|
45
|
-
# Finds records in SimpleDB and returns them as objects of the
|
46
|
-
# current class.
|
47
|
-
#
|
48
|
-
# Finding +:all+ returns an enumerable scope object
|
49
|
-
#
|
50
|
-
# People.find(:all, :order => [:age, :desc], :limit => 10).each do |person|
|
51
|
-
# puts person.name
|
52
|
-
# end
|
53
|
-
#
|
54
|
-
# Finding +:first+ returns a single record (or nil)
|
55
|
-
#
|
56
|
-
# boss = People.find(:first, :where => { :boss => true })
|
57
|
-
#
|
58
|
-
# Find accepts a hash of find modifiers (+:where+, +:order+ and
|
59
|
-
# +:limit+). You can also choose to omit these modifiers and
|
60
|
-
# chain them on the scope object returned. In the following
|
61
|
-
# example only one request is made to SimpleDB (when #each is
|
62
|
-
# called)
|
63
|
-
#
|
64
|
-
# people = People.find(:all)
|
65
|
-
#
|
66
|
-
# johns = people.where(:name => 'John Doe')
|
67
|
-
#
|
68
|
-
# johns.order(:age, :desc).limit(10).each do |suspects|
|
69
|
-
# # ...
|
70
|
-
# end
|
71
|
-
#
|
72
|
-
# See also {#where}, {#order} and {#limit} for more
|
73
|
-
# information and options.
|
74
|
-
#
|
75
|
-
# @overload find(id)
|
76
|
-
# @param id The record to find, raises an exception if the record is
|
77
|
-
# not found.
|
78
|
-
#
|
79
|
-
# @overload find(mode, options = {})
|
80
|
-
# @param [:all,:first] mode (:all) When finding +:all+ matching records
|
81
|
-
# and array is returned of records. When finding +:first+ then
|
82
|
-
# +nil+ or a single record will be returned.
|
83
|
-
# @param [Hash] options
|
84
|
-
# @option options [Mixed] :where Conditions that determine what
|
85
|
-
# records are returned.
|
86
|
-
# @option options [String,Array] :sort The order records should be
|
87
|
-
# returned in.
|
88
|
-
# @option options [Integer] :limit The max number of records to fetch.
|
89
|
-
def find *args
|
90
|
-
_new_scope.find(*args)
|
91
|
-
end
|
92
|
-
|
93
|
-
# Returns a chainable scope object that restricts further scopes to a
|
94
|
-
# particular domain
|
95
|
-
#
|
96
|
-
# Book.domain('shard_3').all.each do |book|
|
97
|
-
# # ...
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# @param [String] domain
|
101
|
-
# @return [Scope] Returns a scope for restricting the domain of subsequent
|
102
|
-
def domain name
|
103
|
-
_new_scope.domain(name)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Returns an enumerable scope object represents all records.
|
107
|
-
#
|
108
|
-
# Book.all.each do |book|
|
109
|
-
# # ...
|
110
|
-
# end
|
111
|
-
#
|
112
|
-
# This method is equivalent to +find(:all)+, and therefore you can also
|
113
|
-
# pass aditional options. See {#find} for more information on what
|
114
|
-
# options you can pass.
|
115
|
-
#
|
116
|
-
# Book.all(:where => { :author' => 'me' }).each do |my_book|
|
117
|
-
# # ...
|
118
|
-
# end
|
119
|
-
#
|
120
|
-
# @return [Scope] Returns an enumerable scope object.
|
121
|
-
def all options = {}
|
122
|
-
_new_scope.find(:all, options)
|
123
|
-
end
|
124
|
-
|
125
|
-
# Counts records in SimpleDB.
|
126
|
-
#
|
127
|
-
# With no arguments, counts all records:
|
128
|
-
#
|
129
|
-
# People.count
|
130
|
-
#
|
131
|
-
# Accepts query options to count a subset of records:
|
132
|
-
#
|
133
|
-
# People.count(:where => { :boss => true })
|
134
|
-
#
|
135
|
-
# You can also count records on a scope object:
|
136
|
-
#
|
137
|
-
# People.find(:all).where(:boss => true).count
|
138
|
-
#
|
139
|
-
# See {#find} and {Scope#count} for more details.
|
140
|
-
#
|
141
|
-
# @param [Hash] options (<code>{}</code>) Options for counting
|
142
|
-
# records.
|
143
|
-
#
|
144
|
-
# @option options [Mixed] :where Conditions that determine what
|
145
|
-
# records are counted.
|
146
|
-
# @option options [Integer] :limit The max number of records to count.
|
147
|
-
def count(options = {})
|
148
|
-
_new_scope.count(options)
|
149
|
-
end
|
150
|
-
alias_method :size, :count
|
151
|
-
|
152
|
-
# @return [Object,nil] Returns the first record found for the current
|
153
|
-
# class. If there are no records in the current classes domain, then
|
154
|
-
# nil is returned.
|
155
|
-
def first options = {}
|
156
|
-
_new_scope.first(options)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Limits which records are retried from SimpleDB when performing a find.
|
160
|
-
#
|
161
|
-
# Simple string condition
|
162
|
-
#
|
163
|
-
# Car.where('color = "red" or color = "blue"').each {|car| ... }
|
164
|
-
#
|
165
|
-
# String with placeholders for quoting params
|
166
|
-
#
|
167
|
-
# Car.where('color = ?', 'red')
|
168
|
-
#
|
169
|
-
# Car.where('color = ? OR style = ?', 'red', 'compact')
|
170
|
-
#
|
171
|
-
# # produces a condition using in, like: WHERE color IN ('red', 'blue')
|
172
|
-
# Car.where('color IN ?', ['red','blue'])
|
173
|
-
#
|
174
|
-
# Hash arguments
|
175
|
-
#
|
176
|
-
# # WHERE age = '40' AND gender = 'male'
|
177
|
-
# People.where(:age => 40, :gender => 'male').each {|person| ... }
|
178
|
-
#
|
179
|
-
# # WHERE name IN ('John', 'Jane')
|
180
|
-
# People.where(:name => ['John', 'Jane']).each{|person| ... }
|
181
|
-
#
|
182
|
-
# Chaining where with other scope modifiers
|
183
|
-
#
|
184
|
-
# # 10 most expensive red cars
|
185
|
-
# Car.where(:color => 'red').order(:price, :desc).limit(10)
|
186
|
-
#
|
187
|
-
# @overload where(conditions_hash)
|
188
|
-
# @overload where(sql_fragment[, quote_params, ...])
|
189
|
-
#
|
190
|
-
# @param [Hash] conditions_hash A hash of attributes to values. Each
|
191
|
-
# key/value pair from the hash becomes a find condition. All conditions
|
192
|
-
# are joined by AND.
|
193
|
-
def where *args
|
194
|
-
_new_scope.where(*args)
|
195
|
-
end
|
196
|
-
|
197
|
-
# Defines the order in which records are returned when performing a find.
|
198
|
-
# SimpleDB only allows sorting by one attribute per request.
|
199
|
-
#
|
200
|
-
# # oldest to youngest
|
201
|
-
# People.order(:age, :desc).each {|person| ... }
|
202
|
-
#
|
203
|
-
# You can chain order with the other scope modifiers:
|
204
|
-
#
|
205
|
-
# Pepole.order(:age, :desc).limit(10).each {|person| ... }
|
206
|
-
#
|
207
|
-
# @overload order(attribute, direction = :asc)
|
208
|
-
# @param [String,Symbol] attribute The attribute in SimpleDB to sort by.
|
209
|
-
# @param [:asc,:desc] direction (:asc) The direction to sort, ascending
|
210
|
-
# or descending order.
|
211
|
-
def order *args
|
212
|
-
_new_scope.order(*args)
|
213
|
-
end
|
214
|
-
|
215
|
-
# The maximum number of records to return. By default, all records
|
216
|
-
# matching the where conditions will be returned from a find.
|
217
|
-
#
|
218
|
-
# People.limit(10).each {|person| ... }
|
219
|
-
#
|
220
|
-
# Limit can be chained with other scope modifiers:
|
221
|
-
#
|
222
|
-
# People.where(:age => 40).limit(10).each {|person| ... }
|
223
|
-
#
|
224
|
-
def limit limit
|
225
|
-
_new_scope.limit(limit)
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
data/lib/aws/record/scopes.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# Copyright 2011-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
|
-
#
|
3
|
-
# Licensed under the Apache License, Version 2.0 (the "License"). You
|
4
|
-
# may not use this file except in compliance with the License. A copy of
|
5
|
-
# the License is located at
|
6
|
-
#
|
7
|
-
# http://aws.amazon.com/apache2.0/
|
8
|
-
#
|
9
|
-
# or in the "license" file accompanying this file. This file is
|
10
|
-
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
|
11
|
-
# ANY KIND, either express or implied. See the License for the specific
|
12
|
-
# language governing permissions and limitations under the License.
|
13
|
-
|
14
|
-
require 'aws/simple_db'
|
15
|
-
require 'aws/record/scope'
|
16
|
-
|
17
|
-
module AWS
|
18
|
-
module Record
|
19
|
-
|
20
|
-
module Scopes
|
21
|
-
|
22
|
-
# Adds a scoped finder method to this class. Given a call
|
23
|
-
# to scope like:
|
24
|
-
#
|
25
|
-
# scope :top_10, order(:popularity, :desc).limit(10)
|
26
|
-
#
|
27
|
-
# Then you can call the method +top_10+ on the class and it will
|
28
|
-
# return an enumerable scope object with the given find conditions.
|
29
|
-
#
|
30
|
-
# @param [Symbol] name The name of the scope. Scope names should be
|
31
|
-
# method-safe and should not conflict with any other class methods.
|
32
|
-
#
|
33
|
-
def scope name, scope = nil, &block
|
34
|
-
|
35
|
-
raise ArgumentError, "only a scope or block may be passed, not both" if
|
36
|
-
scope and block_given?
|
37
|
-
|
38
|
-
method_definition = scope ?
|
39
|
-
lambda{ scope } :
|
40
|
-
block
|
41
|
-
|
42
|
-
extend(Module.new { define_method(name, &method_definition) })
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [Scope] Returns a new scope object for this class.
|
47
|
-
# @private
|
48
|
-
private
|
49
|
-
def _new_scope
|
50
|
-
Scope.new(self)
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|