aws-sdk 1.0.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/.yardopts +6 -0
- data/LICENSE.txt +171 -0
- data/NOTICE.txt +2 -0
- data/README.rdoc +189 -0
- data/lib/aws-sdk.rb +14 -0
- data/lib/aws.rb +63 -0
- data/lib/aws/api_config.rb +45 -0
- data/lib/aws/api_config/.document +0 -0
- data/lib/aws/api_config/EC2-2011-02-28.yml +2314 -0
- data/lib/aws/api_config/SNS-2010-03-31.yml +171 -0
- data/lib/aws/api_config/SQS-2009-02-01.yml +161 -0
- data/lib/aws/api_config/SimpleDB-2009-04-15.yml +278 -0
- data/lib/aws/api_config/SimpleEmailService-2010-12-01.yml +147 -0
- data/lib/aws/api_config_transform.rb +32 -0
- data/lib/aws/async_handle.rb +90 -0
- data/lib/aws/authorize_v2.rb +37 -0
- data/lib/aws/authorize_v3.rb +37 -0
- data/lib/aws/base_client.rb +524 -0
- data/lib/aws/cacheable.rb +92 -0
- data/lib/aws/common.rb +228 -0
- data/lib/aws/configurable.rb +36 -0
- data/lib/aws/configuration.rb +272 -0
- data/lib/aws/configured_client_methods.rb +81 -0
- data/lib/aws/configured_grammars.rb +65 -0
- data/lib/aws/configured_option_grammars.rb +46 -0
- data/lib/aws/configured_xml_grammars.rb +47 -0
- data/lib/aws/default_signer.rb +38 -0
- data/lib/aws/ec2.rb +321 -0
- data/lib/aws/ec2/attachment.rb +149 -0
- data/lib/aws/ec2/attachment_collection.rb +57 -0
- data/lib/aws/ec2/availability_zone.rb +80 -0
- data/lib/aws/ec2/availability_zone_collection.rb +47 -0
- data/lib/aws/ec2/block_device_mappings.rb +53 -0
- data/lib/aws/ec2/client.rb +54 -0
- data/lib/aws/ec2/client/xml.rb +127 -0
- data/lib/aws/ec2/collection.rb +39 -0
- data/lib/aws/ec2/config_transform.rb +63 -0
- data/lib/aws/ec2/elastic_ip.rb +107 -0
- data/lib/aws/ec2/elastic_ip_collection.rb +85 -0
- data/lib/aws/ec2/errors.rb +29 -0
- data/lib/aws/ec2/filtered_collection.rb +65 -0
- data/lib/aws/ec2/has_permissions.rb +46 -0
- data/lib/aws/ec2/image.rb +245 -0
- data/lib/aws/ec2/image_collection.rb +235 -0
- data/lib/aws/ec2/instance.rb +515 -0
- data/lib/aws/ec2/instance_collection.rb +276 -0
- data/lib/aws/ec2/key_pair.rb +86 -0
- data/lib/aws/ec2/key_pair_collection.rb +102 -0
- data/lib/aws/ec2/permission_collection.rb +177 -0
- data/lib/aws/ec2/region.rb +81 -0
- data/lib/aws/ec2/region_collection.rb +55 -0
- data/lib/aws/ec2/request.rb +27 -0
- data/lib/aws/ec2/reserved_instances.rb +50 -0
- data/lib/aws/ec2/reserved_instances_collection.rb +44 -0
- data/lib/aws/ec2/reserved_instances_offering.rb +55 -0
- data/lib/aws/ec2/reserved_instances_offering_collection.rb +43 -0
- data/lib/aws/ec2/resource.rb +340 -0
- data/lib/aws/ec2/resource_tag_collection.rb +218 -0
- data/lib/aws/ec2/security_group.rb +246 -0
- data/lib/aws/ec2/security_group/ip_permission.rb +70 -0
- data/lib/aws/ec2/security_group/ip_permission_collection.rb +59 -0
- data/lib/aws/ec2/security_group_collection.rb +132 -0
- data/lib/aws/ec2/snapshot.rb +138 -0
- data/lib/aws/ec2/snapshot_collection.rb +90 -0
- data/lib/aws/ec2/tag.rb +88 -0
- data/lib/aws/ec2/tag_collection.rb +114 -0
- data/lib/aws/ec2/tagged_collection.rb +48 -0
- data/lib/aws/ec2/tagged_item.rb +87 -0
- data/lib/aws/ec2/volume.rb +190 -0
- data/lib/aws/ec2/volume_collection.rb +95 -0
- data/lib/aws/errors.rb +129 -0
- data/lib/aws/http/builtin_handler.rb +69 -0
- data/lib/aws/http/curb_handler.rb +123 -0
- data/lib/aws/http/handler.rb +77 -0
- data/lib/aws/http/httparty_handler.rb +61 -0
- data/lib/aws/http/request.rb +136 -0
- data/lib/aws/http/request_param.rb +63 -0
- data/lib/aws/http/response.rb +75 -0
- data/lib/aws/ignore_result_element.rb +38 -0
- data/lib/aws/indifferent_hash.rb +86 -0
- data/lib/aws/inflection.rb +46 -0
- data/lib/aws/lazy_error_classes.rb +64 -0
- data/lib/aws/meta_utils.rb +43 -0
- data/lib/aws/model.rb +57 -0
- data/lib/aws/naming.rb +32 -0
- data/lib/aws/option_grammar.rb +544 -0
- data/lib/aws/policy.rb +912 -0
- data/lib/aws/rails.rb +209 -0
- data/lib/aws/record.rb +79 -0
- data/lib/aws/record/attribute.rb +94 -0
- data/lib/aws/record/attribute_macros.rb +288 -0
- data/lib/aws/record/attributes/boolean.rb +49 -0
- data/lib/aws/record/attributes/datetime.rb +86 -0
- data/lib/aws/record/attributes/float.rb +48 -0
- data/lib/aws/record/attributes/integer.rb +68 -0
- data/lib/aws/record/attributes/sortable_float.rb +60 -0
- data/lib/aws/record/attributes/sortable_integer.rb +95 -0
- data/lib/aws/record/attributes/string.rb +69 -0
- data/lib/aws/record/base.rb +728 -0
- data/lib/aws/record/conversion.rb +38 -0
- data/lib/aws/record/dirty_tracking.rb +286 -0
- data/lib/aws/record/errors.rb +153 -0
- data/lib/aws/record/exceptions.rb +48 -0
- data/lib/aws/record/finder_methods.rb +262 -0
- data/lib/aws/record/naming.rb +31 -0
- data/lib/aws/record/scope.rb +157 -0
- data/lib/aws/record/validations.rb +653 -0
- data/lib/aws/record/validator.rb +237 -0
- data/lib/aws/record/validators/acceptance.rb +51 -0
- data/lib/aws/record/validators/block.rb +38 -0
- data/lib/aws/record/validators/confirmation.rb +43 -0
- data/lib/aws/record/validators/count.rb +108 -0
- data/lib/aws/record/validators/exclusion.rb +43 -0
- data/lib/aws/record/validators/format.rb +57 -0
- data/lib/aws/record/validators/inclusion.rb +56 -0
- data/lib/aws/record/validators/length.rb +107 -0
- data/lib/aws/record/validators/numericality.rb +138 -0
- data/lib/aws/record/validators/presence.rb +45 -0
- data/lib/aws/resource_cache.rb +39 -0
- data/lib/aws/response.rb +113 -0
- data/lib/aws/response_cache.rb +50 -0
- data/lib/aws/s3.rb +109 -0
- data/lib/aws/s3/access_control_list.rb +252 -0
- data/lib/aws/s3/acl_object.rb +266 -0
- data/lib/aws/s3/bucket.rb +320 -0
- data/lib/aws/s3/bucket_collection.rb +122 -0
- data/lib/aws/s3/bucket_version_collection.rb +85 -0
- data/lib/aws/s3/client.rb +999 -0
- data/lib/aws/s3/client/xml.rb +190 -0
- data/lib/aws/s3/data_options.rb +99 -0
- data/lib/aws/s3/errors.rb +43 -0
- data/lib/aws/s3/multipart_upload.rb +318 -0
- data/lib/aws/s3/multipart_upload_collection.rb +78 -0
- data/lib/aws/s3/object_collection.rb +159 -0
- data/lib/aws/s3/object_metadata.rb +67 -0
- data/lib/aws/s3/object_upload_collection.rb +83 -0
- data/lib/aws/s3/object_version.rb +141 -0
- data/lib/aws/s3/object_version_collection.rb +78 -0
- data/lib/aws/s3/paginated_collection.rb +94 -0
- data/lib/aws/s3/policy.rb +76 -0
- data/lib/aws/s3/prefix_and_delimiter_collection.rb +56 -0
- data/lib/aws/s3/prefixed_collection.rb +84 -0
- data/lib/aws/s3/presigned_post.rb +504 -0
- data/lib/aws/s3/request.rb +198 -0
- data/lib/aws/s3/s3_object.rb +794 -0
- data/lib/aws/s3/tree.rb +116 -0
- data/lib/aws/s3/tree/branch_node.rb +71 -0
- data/lib/aws/s3/tree/child_collection.rb +108 -0
- data/lib/aws/s3/tree/leaf_node.rb +99 -0
- data/lib/aws/s3/tree/node.rb +22 -0
- data/lib/aws/s3/tree/parent.rb +90 -0
- data/lib/aws/s3/uploaded_part.rb +82 -0
- data/lib/aws/s3/uploaded_part_collection.rb +86 -0
- data/lib/aws/service_interface.rb +60 -0
- data/lib/aws/simple_db.rb +202 -0
- data/lib/aws/simple_db/attribute.rb +159 -0
- data/lib/aws/simple_db/attribute_collection.rb +227 -0
- data/lib/aws/simple_db/client.rb +52 -0
- data/lib/aws/simple_db/client/options.rb +34 -0
- data/lib/aws/simple_db/client/xml.rb +68 -0
- data/lib/aws/simple_db/consistent_read_option.rb +42 -0
- data/lib/aws/simple_db/delete_attributes.rb +64 -0
- data/lib/aws/simple_db/domain.rb +118 -0
- data/lib/aws/simple_db/domain_collection.rb +116 -0
- data/lib/aws/simple_db/domain_metadata.rb +112 -0
- data/lib/aws/simple_db/errors.rb +46 -0
- data/lib/aws/simple_db/expect_condition_option.rb +45 -0
- data/lib/aws/simple_db/item.rb +84 -0
- data/lib/aws/simple_db/item_collection.rb +594 -0
- data/lib/aws/simple_db/item_data.rb +70 -0
- data/lib/aws/simple_db/put_attributes.rb +62 -0
- data/lib/aws/simple_db/request.rb +27 -0
- data/lib/aws/simple_email_service.rb +373 -0
- data/lib/aws/simple_email_service/client.rb +39 -0
- data/lib/aws/simple_email_service/client/options.rb +24 -0
- data/lib/aws/simple_email_service/client/xml.rb +38 -0
- data/lib/aws/simple_email_service/email_address_collection.rb +66 -0
- data/lib/aws/simple_email_service/errors.rb +29 -0
- data/lib/aws/simple_email_service/quotas.rb +64 -0
- data/lib/aws/simple_email_service/request.rb +27 -0
- data/lib/aws/sns.rb +69 -0
- data/lib/aws/sns/client.rb +37 -0
- data/lib/aws/sns/client/options.rb +24 -0
- data/lib/aws/sns/client/xml.rb +38 -0
- data/lib/aws/sns/errors.rb +29 -0
- data/lib/aws/sns/policy.rb +49 -0
- data/lib/aws/sns/request.rb +27 -0
- data/lib/aws/sns/subscription.rb +100 -0
- data/lib/aws/sns/subscription_collection.rb +84 -0
- data/lib/aws/sns/topic.rb +384 -0
- data/lib/aws/sns/topic_collection.rb +70 -0
- data/lib/aws/sns/topic_subscription_collection.rb +58 -0
- data/lib/aws/sqs.rb +70 -0
- data/lib/aws/sqs/client.rb +38 -0
- data/lib/aws/sqs/client/xml.rb +36 -0
- data/lib/aws/sqs/errors.rb +33 -0
- data/lib/aws/sqs/policy.rb +50 -0
- data/lib/aws/sqs/queue.rb +507 -0
- data/lib/aws/sqs/queue_collection.rb +105 -0
- data/lib/aws/sqs/received_message.rb +184 -0
- data/lib/aws/sqs/received_sns_message.rb +112 -0
- data/lib/aws/sqs/request.rb +44 -0
- data/lib/aws/xml_grammar.rb +923 -0
- data/rails/init.rb +15 -0
- metadata +298 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attribute'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class BooleanAttribute < Attribute
|
|
21
|
+
|
|
22
|
+
def self.type_cast raw_value, options = {}
|
|
23
|
+
case raw_value
|
|
24
|
+
when nil then nil
|
|
25
|
+
when '' then nil
|
|
26
|
+
when false, 'false', '0', 0 then false
|
|
27
|
+
else true
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.serialize boolean, options = {}
|
|
32
|
+
case boolean
|
|
33
|
+
when false then '0'
|
|
34
|
+
when true then '1'
|
|
35
|
+
else
|
|
36
|
+
msg = "expected a boolean value, got #{boolean.class}"
|
|
37
|
+
raise ArgumentError, msg
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @private
|
|
42
|
+
def self.allow_set?
|
|
43
|
+
false
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attribute'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class DateTimeAttribute < Attribute
|
|
21
|
+
|
|
22
|
+
# Returns value cast to a DateTime object. Empty strings are cast to
|
|
23
|
+
# nil. Values are cast first to strings and then passed to
|
|
24
|
+
# DateTime.parse. Integers are treated as timestamps.
|
|
25
|
+
#
|
|
26
|
+
# datetime_attribute.type_cast('2000-01-02')
|
|
27
|
+
# #=> #<DateTime: 4903091/2,0,2299161>
|
|
28
|
+
#
|
|
29
|
+
# datetime_attribute.type_cast(1306170146)
|
|
30
|
+
# #<DateTime: 106086465073/43200,-7/24,2299161>
|
|
31
|
+
#
|
|
32
|
+
# datetime_attribute.type_cast('')
|
|
33
|
+
# #=> nil
|
|
34
|
+
#
|
|
35
|
+
# datetime_attribute.type_cast(nil)
|
|
36
|
+
# #=> nil
|
|
37
|
+
#
|
|
38
|
+
# @param [Mixed] raw_value The value to cast to a DateTime object.
|
|
39
|
+
# @param [Hash] options
|
|
40
|
+
# @return [DateTime,nil]
|
|
41
|
+
def self.type_cast raw_value, options = {}
|
|
42
|
+
case raw_value
|
|
43
|
+
when nil then nil
|
|
44
|
+
when '' then nil
|
|
45
|
+
when DateTime then raw_value
|
|
46
|
+
when Integer then
|
|
47
|
+
begin
|
|
48
|
+
DateTime.parse(Time.at(raw_value).to_s) # timestamp
|
|
49
|
+
rescue
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
begin
|
|
54
|
+
DateTime.parse(raw_value.to_s) # Time, Date or String
|
|
55
|
+
rescue
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Returns a DateTime object encoded as a string (suitable for sorting).
|
|
62
|
+
#
|
|
63
|
+
# attribute.serialize(DateTime.parse('2001-01-01'))
|
|
64
|
+
# #=> '2001-01-01T00:00:00:Z)
|
|
65
|
+
#
|
|
66
|
+
# @param [DateTime] datetime The datetime object to serialize.
|
|
67
|
+
# @param [Hash] options
|
|
68
|
+
# @return [String] Returns the datetime object serialized to a string
|
|
69
|
+
# in ISO8601 format (e.g. '2011-01-02T10:11:12Z')
|
|
70
|
+
def self.serialize datetime, options = {}
|
|
71
|
+
unless datetime.is_a?(DateTime)
|
|
72
|
+
msg = "expected a DateTime value, got #{datetime.class}"
|
|
73
|
+
raise ArgumentError, msg
|
|
74
|
+
end
|
|
75
|
+
datetime.strftime('%Y-%m-%dT%H:%M:%S%Z')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# @private
|
|
79
|
+
def self.allow_set?
|
|
80
|
+
true
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attribute'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class FloatAttribute < Attribute
|
|
21
|
+
|
|
22
|
+
def self.type_cast raw_value, options = {}
|
|
23
|
+
case raw_value
|
|
24
|
+
when nil then nil
|
|
25
|
+
when '' then nil
|
|
26
|
+
when Float then raw_value
|
|
27
|
+
else
|
|
28
|
+
raw_value.respond_to?(:to_f) ?
|
|
29
|
+
raw_value.to_f :
|
|
30
|
+
raw_value.to_s.to_f
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def self.serialize float, options = {}
|
|
35
|
+
expect(Float, float) do
|
|
36
|
+
float.to_s
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @private
|
|
41
|
+
def self.allow_set?
|
|
42
|
+
true
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attribute'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class IntegerAttribute < Attribute
|
|
21
|
+
|
|
22
|
+
# Returns value cast to an integer. Empty strings are cast to
|
|
23
|
+
# nil by default. Type casting is done by calling #to_i on the value.
|
|
24
|
+
#
|
|
25
|
+
# int_attribute.type_cast('123')
|
|
26
|
+
# #=> 123
|
|
27
|
+
#
|
|
28
|
+
# int_attribute.type_cast('')
|
|
29
|
+
# #=> nil
|
|
30
|
+
#
|
|
31
|
+
# @param [Mixed] value The value to type cast to an integer.
|
|
32
|
+
# @return [Integer,nil] Returns the type casted integer or nil
|
|
33
|
+
def self.type_cast raw_value, options = {}
|
|
34
|
+
case raw_value
|
|
35
|
+
when nil then nil
|
|
36
|
+
when '' then nil
|
|
37
|
+
when Integer then raw_value
|
|
38
|
+
else
|
|
39
|
+
raw_value.respond_to?(:to_i) ?
|
|
40
|
+
raw_value.to_i :
|
|
41
|
+
raw_value.to_s.to_i
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Returns a serialized representation of the integer value suitable for
|
|
46
|
+
# storing in SimpleDB.
|
|
47
|
+
#
|
|
48
|
+
# attribute.serialize(123)
|
|
49
|
+
# #=> '123'
|
|
50
|
+
#
|
|
51
|
+
# @param [Integer] integer The number to serialize.
|
|
52
|
+
# @param [Hash] options
|
|
53
|
+
# @return [String] A serialized representation of the integer.
|
|
54
|
+
def self.serialize integer, options = {}
|
|
55
|
+
expect(Integer, integer) do
|
|
56
|
+
integer.to_s
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @private
|
|
61
|
+
def self.allow_set?
|
|
62
|
+
true
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attribute'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class SortableFloatAttribute < FloatAttribute
|
|
21
|
+
|
|
22
|
+
def initialize name, options = {}
|
|
23
|
+
|
|
24
|
+
range = options[:range]
|
|
25
|
+
raise ArgumentError, "missing required option :range" unless range
|
|
26
|
+
raise ArgumentError, ":range should be an integer range" unless
|
|
27
|
+
range.is_a?(Range) and range.first.is_a?(Integer)
|
|
28
|
+
|
|
29
|
+
super(name, options)
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def self.serialize float, options = {}
|
|
34
|
+
expect(Float, float) do
|
|
35
|
+
|
|
36
|
+
left, right = float.to_s.split('.')
|
|
37
|
+
|
|
38
|
+
left = SortableIntegerAttribute.serialize(left.to_i, options)
|
|
39
|
+
|
|
40
|
+
SortableIntegerAttribute.check_range(float, options)
|
|
41
|
+
|
|
42
|
+
"#{left}.#{right}"
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.deserialize string_value, options = {}
|
|
48
|
+
|
|
49
|
+
left, right = float.to_s.split('.')
|
|
50
|
+
|
|
51
|
+
left = SortableIntegerAttribute.deserialize(left, options)
|
|
52
|
+
|
|
53
|
+
"#{left}.#{right}".to_f
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attributes/integer'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class SortableIntegerAttribute < IntegerAttribute
|
|
21
|
+
|
|
22
|
+
def initialize name, options = {}
|
|
23
|
+
|
|
24
|
+
range = options[:range]
|
|
25
|
+
raise ArgumentError, "missing required option :range" unless range
|
|
26
|
+
raise ArgumentError, ":range should be a integer range" unless
|
|
27
|
+
range.is_a?(Range) and range.first.is_a?(Integer)
|
|
28
|
+
|
|
29
|
+
super(name, options)
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns a serialized representation of the integer value suitable for
|
|
34
|
+
# storing in SimpleDB.
|
|
35
|
+
#
|
|
36
|
+
# attribute.serialize(123)
|
|
37
|
+
# #=> '123'
|
|
38
|
+
#
|
|
39
|
+
# # padded to the correct number of digits
|
|
40
|
+
# attribute.serialize('123', :range => (0..10_000)
|
|
41
|
+
# #=> '00123'
|
|
42
|
+
#
|
|
43
|
+
# # offset applied to make all values positive
|
|
44
|
+
# attribute.serialize('-55', :range => (-100..10_000)
|
|
45
|
+
# #=> '00045'
|
|
46
|
+
#
|
|
47
|
+
# @param [Integer] integer The number to serialize.
|
|
48
|
+
# @param [Hash] options
|
|
49
|
+
# @option options [required,Range] :range A range that represents the
|
|
50
|
+
# minimum and maximum values this integer can be.
|
|
51
|
+
# The returned value will have an offset applied (if min is
|
|
52
|
+
# less than 0) and will be zero padded.
|
|
53
|
+
# @return [String] A serialized representation of the integer.
|
|
54
|
+
def self.serialize integer, options = {}
|
|
55
|
+
expect(Integer, integer) do
|
|
56
|
+
check_range(integer, options)
|
|
57
|
+
offset_and_precision(options) do |offset,precision|
|
|
58
|
+
"%0#{precision}d" % (integer.to_i + offset)
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.deserialize string_value, options = {}
|
|
64
|
+
offset_and_precision(options) do |offset,precision|
|
|
65
|
+
string_value.to_i - offset
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# @private
|
|
70
|
+
protected
|
|
71
|
+
def self.offset_and_precision options, &block
|
|
72
|
+
|
|
73
|
+
min = options[:range].first
|
|
74
|
+
max = options[:range].last
|
|
75
|
+
|
|
76
|
+
offset = min < 0 ? min * -1 : 0
|
|
77
|
+
precision = (max + offset).to_s.length
|
|
78
|
+
|
|
79
|
+
yield(offset, precision)
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# @private
|
|
84
|
+
def self.check_range number, options
|
|
85
|
+
unless options[:range].include?(number)
|
|
86
|
+
msg = "unable to serialize `#{number}`, falls outside " +
|
|
87
|
+
"the range #{options[:range]}"
|
|
88
|
+
raise msg
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Copyright 2011 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/record/attribute'
|
|
15
|
+
|
|
16
|
+
module AWS
|
|
17
|
+
module Record
|
|
18
|
+
|
|
19
|
+
# @private
|
|
20
|
+
class StringAttribute < Attribute
|
|
21
|
+
|
|
22
|
+
# Returns the value cast to a string. Empty strings are returned as
|
|
23
|
+
# nil by default. Type casting is done by calling #to_s on the value.
|
|
24
|
+
#
|
|
25
|
+
# string_attr.type_cast(123)
|
|
26
|
+
# # => '123'
|
|
27
|
+
#
|
|
28
|
+
# string_attr.type_cast('')
|
|
29
|
+
# # => nil
|
|
30
|
+
#
|
|
31
|
+
# string_attr.type_cast('', :preserve_empty_strings => true)
|
|
32
|
+
# # => ''
|
|
33
|
+
#
|
|
34
|
+
# @param [Mixed] value
|
|
35
|
+
# @param [Hash] options
|
|
36
|
+
# @option options [Boolean] :preserve_empty_strings (false) When true,
|
|
37
|
+
# empty strings are preserved and not cast to nil.
|
|
38
|
+
# @return [String,nil] The type casted value.
|
|
39
|
+
def self.type_cast raw_value, options = {}
|
|
40
|
+
case raw_value
|
|
41
|
+
when nil then nil
|
|
42
|
+
when '' then options[:preserve_empty_strings] ? '' : nil
|
|
43
|
+
when String then raw_value
|
|
44
|
+
else raw_value.to_s
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Returns a serialized representation of the string value suitable for
|
|
49
|
+
# storing in SimpleDB.
|
|
50
|
+
# @param [String] string
|
|
51
|
+
# @param [Hash] options
|
|
52
|
+
# @return [String] The serialized string.
|
|
53
|
+
def self.serialize string, options = {}
|
|
54
|
+
unless string.is_a?(String)
|
|
55
|
+
msg = "expected a String value, got #{string.class}"
|
|
56
|
+
raise ArgumentError, msg
|
|
57
|
+
end
|
|
58
|
+
string
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @private
|
|
62
|
+
def self.allow_set?
|
|
63
|
+
true
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
end
|